ContentDialog PrimaryButtonClick closes the dialog before the async operation completes.

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

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)
No comments
{count} votes

Accepted answer
  1. answered 2020-04-24T01:27:35.443+00:00
    Gavin 116 Reputation points

    Okay, found the solution. I need to use args.GetDeferral();

    No comments

1 additional answer

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

    smoething Please help the Asp.net Malware functon!

    No comments