0

I have a little button code like this:

private void CreateButton_Click(object sender, RoutedEventArgs e)
{
    var MsgDialog = new MessageDialog("MY MESSAGE");
    MsgDialog.Commands.Add(new UICommand("OK", (UICommandInvokedHandler) =>
        {
            // IF USER PRESSES OK, CHECKBOX WILL GET CHECKED
            DontDisplayCheckBox.IsChecked = true;
        }));

       // DISPLAY MESSAGE IF TEXTBOX IS EMPTY
    if (TileName.Text == "")
        MsgDialog.ShowAsync();
    else
        // REST OF THE CODE;
}

The code works but it keeps giving me a warning:

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Should/could I just ignore it? If not, how to I implement the 'await' operator in this case?

svick
  • 236,525
  • 50
  • 385
  • 514
gabrieljcs
  • 689
  • 6
  • 13
  • See this for the reason not to ignore the warning: http://stackoverflow.com/questions/11147187/am-i-right-to-ignore-the-compiler-warning-for-lacking-await-for-this-async-call – DasKrümelmonster May 12 '13 at 15:23

1 Answers1

3

add async to the method defintion

private async void CreateButton_Click(object sender, RoutedEventArgs e)

and add await to

await MsgDialog.ShowAsync();
I4V
  • 34,891
  • 6
  • 67
  • 79