How can I use Messagebox.Show in an asynchronous method on Windows Phone 8?

The exception thrown in the MessageBox. How can I use MessageBox in async method?

private async void Purchheard(object sender,EventArgs e){ Debug.WriteLine(" "); try{ await CurrentApp.RequestProductPurchaseAsync(ID,false); if(license.ProductLicenses[ID].IsActive){world.is_freemium=false;} }catch (Exception ex){ MessageBox.Show("Finished!"); } 
+6
source share
2 answers
 Dispatcher.BeginInvoke(delegate(){messagebox.show("your stuff");}); 
+2
source

Not sure why accepted answer doesn't work, but here is a working example for .NET 4.5

 var dg = new Action(() => { MessageBox.Show(msg, name); }); Dispatcher.CurrentDispatcher.BeginInvoke(dg); 

Anonymous Methods and Delegates

CS0120: Object reference required for non-static field, method or 'foo' property

+3
source

Source: https://habr.com/ru/post/952727/


All Articles