如何在Windows Phone 8上的异步方法中使用Messagebox.Show?

时间:2013-08-29 09:44:24

标签: c# windows-phone-8

MessageBox上生成异常。如何在MessageBox方法中使用async

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

2 个答案:

答案 0 :(得分:4)

不确定为什么接受的答案不起作用,但这是.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'

答案 1 :(得分:2)

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