await MessageDialog in the body of a catch clause

A major disadvantage of using MessageDialog is that you need to await it to show the messagebox and when often you would need to display error messages in the catch clause.

In normal situation you would be doing the below:
MessageDialog messagedialog = new MessageDialog(ex.Message);
await messagedialog.ShowAsync();

However the catch clause does not allow the use of await. To overcome this, you would need a create the below helper class to continue displaying the error message.

    public class MessageDialogHelper
        public static async void Show(string content, string title)
            MessageDialog messageDialog = new MessageDialog(content, title);
            await messageDialog.ShowAsync();

With the below, you could then use the MessageDialog as below.

MessageDialogHelper.Show("Show Msg");
This entry was posted in C#, Windows Phone, winrt and tagged , , , , . Bookmark the permalink.

5 Responses to await MessageDialog in the body of a catch clause

  1. Pingback: C# 6 Features – “Await in catch and finally blocks.” | TechCentral

  2. mzitoxyz says:

    Reblogged this on univinforepos and commented:


  3. Asking questions are really good thing if you are not understanding anything totally, but this article presents pleasant understanding

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s