locked
How do I make MessageDialog's ShowAsync method synchronous?

    Question

  • I am trying to create a Yes/No user input required MessageDialog in a Windows 8 Metro App.  When I try to await the dialog's ShowAsync method, the UI thread locks up.  If I let it run async, the UI thread is fine, but I return without having the user's selection (Yes or No).  How can I wait on the ShowAsync method and return only once I have determine what IUICommand the user has selected?

    Thanks in advance for your advice.

    Thursday, June 20, 2013 11:46 AM

Answers

All replies

  • await ShowAsync() shouldnt lock the ui thread. have an sample project?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, June 20, 2013 11:56 AM
  • Thanks for the quick response.  I just put together a sample project and noticed that if I put the code to call/await the MessageDialog in my code behind (xaml.cs) that the dialog shows up, the UI thread is fine and all is well.  If I move the call that's displays the dialog to a method in another class - this is where I get the behavior where the dialog doesn't show and the UI seems to lock up.  Do I need to use the App's dispatcher to make this work outside of a code behind class? 

    Thanks again for the help.

    Thursday, June 20, 2013 12:18 PM
  • Hi CHI MS DEV

    Have you ever read this article? http://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx . I think it will give you some hint for your solution, for instance the "completed" statue maybe used by your code.

    Good luck.


    James He
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 26, 2013 3:23 AM
    Moderator