【问题标题】:The 'await' operator can only be used within an async lambda expression Windows Phone 8'await' 运算符只能在异步 lambda 表达式 Windows Phone 8 中使用
【发布时间】:2014-05-29 13:57:35
【问题描述】:

我在CustomMessageBox 左键单击结束时调用异步方法。但它给了我编译时间错误。我搜索了它,但得到了一些关于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();           

    }

谁能建议我如何实现这一目标?

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    尝试像错误所说的那样 - 使用async lambda expression

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

    【讨论】:

      猜你喜欢
      • 2014-01-02
      • 2016-02-08
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2020-05-26
      相关资源
      最近更新 更多