Skip to main content
 首页 » 编程设计

c#之'await' 运算符只能在异步 lambda 表达式中使用 Windows Phone 8

2024年02月13日14emanlee

我在 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();            
 
    } 

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

提前致谢。

请您参考如下方法:

按照错误提示尝试 - 使用异步 lambda 表达式:

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