2013-08-29 9 views
6

Eccezione generata su MessageBox. Come posso usare MessageBox in modo asincrono?Come posso utilizzare Messagebox.Show in modalità asincrona su Windows Phone 8?

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!"); 
      } 
+0

Qual è l'eccezione ? – Sean

+3

'Dispatcher.Invoke (() => MessageBox.Show (" whatever "));' –

+1

Dispatcher.BeginInvoke (() => MessageBox.Show ("qualunque cosa")); Grazie – Vladislav

risposta

2
Dispatcher.BeginInvoke(delegate(){messagebox.show("your stuff");}); 
+1

Questo non funziona –

+0

Posso vedere il tuo codice? – gayan1991

+0

@ gayan1991 Impossibile convertire il metodo anonimo in delegato perché non è un tipo delegato ... Non funziona come proposto. – pzogr

3

Non certo perché la risposta accettata non funziona, ma ecco un esempio di lavoro per NET 4,5

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

Anonymous methods and delegates

CS0120: An object reference is required for the nonstatic field, method, or property 'foo'

+0

Questo mantiene il thread principale di esecuzione anche –

+0

Ho anche avuto il requisito di non bloccare il thread principale e questo ha funzionato bene per me. – grinder22

Problemi correlati