Vladislav
Vladislav

Reputation: 297

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

Upvotes: 6

Views: 8039

Answers (2)

gayan1991
gayan1991

Reputation: 795

Dispatcher.BeginInvoke(delegate() { MessageBox.Show("your stuff"); });

Upvotes: 3

he_the_great
he_the_great

Reputation: 6774

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'

Upvotes: 5

Related Questions