ContentDialog PrimaryButtonClick closes the dialog before the async operation completes.

Gavin 116 Reputation points
2020-04-24T01:11:20.68+00:00

Hi

I have a ContentDialog, when I click on the primary button the PrimaryButtonClick event is raised which then calls an async operation. But before the async operation completes the dialog is closed. Is there a way to prevent this?

private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
     IsPrimaryButtonEnabled = IsSecondaryButtonEnabled = false;

     bool result = false;   

     try
     {
          result = await REST.SetOffersAsync();
          if (!result) {
                args.Cancel = true;
                IsSecondaryButtonEnabled = true;
          }
     }
     catch (Exception ex)
     {
          args.Cancel = true;
          IsSecondaryButtonEnabled = true;

     }                  
 }

Thanks

Gavin

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Kevin Aaron 1 Reputation point
    2020-04-24T01:14:40.147+00:00

    smoething Please help the Asp.net Malware functon!

    0 comments No comments