【问题标题】:ContentDialog showAsync() giving error: no definition for getAwaiter [duplicate]ContentDialog showAsync() 给出错误:没有定义 getAwaiter [重复]
【发布时间】:2017-05-31 21:26:41
【问题描述】:

我正在构建一个 UWP 应用程序 (C#),单击按钮时,我想验证输入。 如果验证失败,我想显示一条消息说输入错误。 这是我应该处理的函数:

private async void AddContact_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
    DBHelper db = new DBHelper();
    if(i_name.Text != "" && i_phone.Text != "") {
        db.insertPerson(new Person(i_name.Text, i_phone.Text));
        Frame.Navigate(typeof(MainPage));
    } else {
        ContentDialog msg = new ContentDialog() {
            Title = "Empty input!",
            Content = "Please fill both fields!",
            CloseButtonText = "OK"
        };
        await msg.ShowAsync();
    }
}

但是,当键入最后一部分(await msg.showAsync())时,它会保持红色下划线(在 VS 中)。构建器读取以下错误:

错误 CS4036 “IAsyncOperation”不包含“GetAwaiter”的定义,并且找不到接受“IAsyncOperation”类型的第一个参数的扩展方法“GetAwaiter”(您是否缺少“System”的 using 指令?) testniStudioApp d:...\SecondPage.xaml.cs 43 活动

现在我尝试将此调用分配给变量(因为我看到有人以这种方式解决了类似的问题),但它仍然没有奏效。 然后我尝试按照here 的说明清除 NuGet 缓存并重建项目,但这些解决方案都不起作用。

我很难理解它想从我这里得到什么。 每个关于如何显示消息的教程都或多或少地以相同的方式编写,所以我无法理解可能有什么问题。

【问题讨论】:

标签: c# uwp async-await


【解决方案1】:

using System; 不见了。 感谢cmets的回答

【讨论】:

    猜你喜欢
    • 2020-04-25
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 2018-01-02
    • 2016-11-25
    • 1970-01-01
    • 2018-07-02
    • 2020-10-06
    相关资源
    最近更新 更多