Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i use Messagebox.Show in async method on Windows Phone 8?

Exception generated on 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!");
    }
}
like image 800
Vladislav Avatar asked Aug 29 '13 09:08

Vladislav


2 Answers

Not sure why the 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: An object reference is required for the nonstatic field, method, or property 'foo'

like image 164
he_the_great Avatar answered Sep 18 '22 11:09

he_the_great


Dispatcher.BeginInvoke(delegate() { MessageBox.Show("your stuff"); });
like image 23
gayan1991 Avatar answered Sep 20 '22 11:09

gayan1991