This is a migrated thread and some comments may be shown as answers.

Messagebox won't show

7 Answers 120 Views
MessageBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 08 Dec 2011, 11:06 AM
Hi All

When my app starts for the first time it needs to generate some default data.  In my code I show a message thanking them for purchasing and informing them that default data will then be generated.  When they OK this message the code generates the data and when that has completed another message is shown telling them that the app is ready to use.

However

What happens is, when the app starts the first message is not shown until after the data is created and then the second message is not shown at all.

When I used the original message box it worked fine.

Any ideas?

7 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 08 Dec 2011, 06:09 PM
Hello Paul,

 Thank you for writing.
When you debug the application you should notice that the call to our RadMessageBox.Show() method returns immediately, while Microsoft's message box blocks the UI thread. This is why the standard message box is shown before your data is generated and ours shows after it is generated. In other words, the MessageBox.Show() method is snychronous, while RadMessageBox.Show() is asynchronous.

RadMessageBox is implemented asynchronously because there is no other way to implement it in Silverlight. In order for the Show method to block the UI thread we need low level native APIs that allow the installation of a modal message loop, however these APIs are not available to developers.

What you have to do, is to show RadMessageBox initially. Then, in the message box closed, callback you generate your data. Now after your data is generated, you show the second message box.
For example:

this.Loaded += (s, a) =>
    {
        RadMessageBox.Show("Title", closedHandler: (args) =>
            {
                // generate data.
 
                this.Dispatcher.BeginInvoke(() => RadMessageBox.Show("Second message box"));
            });
    };

Please write again if you have other questions.

Regards,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Paul
Top achievements
Rank 1
answered on 08 Dec 2011, 06:25 PM
Thank you Victor :)
0
Ian
Top achievements
Rank 1
answered on 24 Apr 2012, 08:41 PM
Thanks for this post, it might be worth adding this to the getting started documentation as I was having the same issue when overiding the back button (to ensure that settings were saved).
Ian
0
Ian
Top achievements
Rank 1
answered on 24 Apr 2012, 08:49 PM
oops spoke before trying it, it still doesnt wait my code is:

 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
//check to see if settings have been changed            
string onBackPressSettings = lpConcUnits.SelectedIndex.ToString() + lpVolUnits.SelectedIndex.ToString() + lpMassUnits.SelectedIndex.ToString();


            if (onOpenSettings != onBackPressSettings)
            {
                this.Loaded += (s, a) =>
                RadMessageBox.Show("Title", closedHandler: (args) =>
                {
                    // generate data.


                    this.Dispatcher.BeginInvoke(() => RadMessageBox.Show("Second message box"));
                });
                
                
            }

any help much appreciated
0
Victor
Telerik team
answered on 27 Apr 2012, 12:47 PM
Hi Ian,

 Thanks for writing.
As mentioned earlier, the Show() method of RadMessageBox is asynchronous. Therefore, when you call it on back key press, it returns immediately and you go back to the previous page of your app or the app exits. What you have to do, is when you determine that you should show the message box, you have to cancel the back key press and then show the message box.

Please write again if you need further assistance.

All the best,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Yang
Top achievements
Rank 1
answered on 05 Apr 2013, 11:50 PM
I think that RadMesssageBox.Show() is asynchronous should be mentioned in the documentation at here:
http://www.telerik.com/help/windows-phone/messagebox-gettingstarted-gettingstarted.html
0
Victor
Telerik team
answered on 08 Apr 2013, 12:28 PM
Hello Yang,

Thanks for the feedback. I agree, we will add this bit to the getting started page.

Regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
MessageBox
Asked by
Paul
Top achievements
Rank 1
Answers by
Victor
Telerik team
Paul
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Yang
Top achievements
Rank 1
Share this question
or