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

Vla*_*lav 6 c# windows-phone-8

生成异常MessageBox.我怎样才能MessageBoxasync方法中使用?

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!");
    }
}
Run Code Online (Sandbox Code Playgroud)

he_*_*eat 5

不知道为什么接受的答案不起作用,但这是 .NET 4.5 的一个工作示例

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

匿名方法和委托

CS0120:非静态字段、方法或属性“foo”需要对象引用


gay*_*991 3

Dispatcher.BeginInvoke(delegate() { MessageBox.Show("your stuff"); });
Run Code Online (Sandbox Code Playgroud)