Messagebox won't show

8 posts, 0 answers
  1. Paul
    Paul avatar
    9 posts
    Member since:
    Dec 2011

    Posted 08 Dec 2011 Link to this post

    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?
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 08 Dec 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Paul
    Paul avatar
    9 posts
    Member since:
    Dec 2011

    Posted 08 Dec 2011 Link to this post

    Thank you Victor :)
  5. Ian
    Ian avatar
    2 posts
    Member since:
    Feb 2012

    Posted 24 Apr 2012 Link to this post

    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
  6. Ian
    Ian avatar
    2 posts
    Member since:
    Feb 2012

    Posted 24 Apr 2012 Link to this post

    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
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 27 Apr 2012 Link to this post

    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 >>

  8. Yang
    Yang avatar
    16 posts
    Member since:
    Apr 2012

    Posted 05 Apr 2013 Link to this post

    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
  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 08 Apr 2013 Link to this post

    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.
Back to Top
DevCraft banner