等待'等待'运算符只能在异步lambda表达式Windows Phone 8中使用

时间:2014-05-29 13:57:35

标签: c# windows-phone-8 windows-phone async-await windows-phone-toolkit

我在调用CustomMessageBox左键单击时调用异步方法。但它给了我complie时间错误。我搜索了它,但获得了有关MessageDialog.Command的一些信息。我将如何在Windows Phone CustomMessageBox中实现相同目标。

这是我的代码

CustomMessageBox customMBox = new CustomMessageBox()
                {
                    Caption = "Alert!",
                    Message = string.Format("Clicking on clear all will clear all the data on the app. Are you sure you want to proceed?"),
                    LeftButtonContent = "Yes",
                    RightButtonContent = "No",
                };

                customMBox.Dismissed += (s2, e2) =>
                {
                    switch (e2.Result)
                    {
                        case CustomMessageBoxResult.LeftButton:
                            await clearDatabaseAsync();
                            break;
                        case CustomMessageBoxResult.RightButton:
                            break;
                        case CustomMessageBoxResult.None:
                            break;
                        default:
                            break;
                    }
                };

                customMBox.Show();

    public async Task clearDatabaseAsync()
    {
       //SQLite clear table record logic
        await App.DeleteDatabase();           

    }

任何人都可以建议我如何实现这一目标吗?

先谢谢。

1 个答案:

答案 0 :(得分:4)

尝试错误说 - 使用async lambda expression

customMBox.Dismissed += async (s2, e2) => // rest of the code ...