这个问题已经在这里有一个答案:
我使用Visual Studio 2017年专业。
我的问题代码如下:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Notifications;
using System;
namespace SeleniumWebChat.Utilities
{
// This class handles Windows 'Toast' notifications that pop up when a new webchat/call is received
static class WinNotificationHandler
{
static async Task<bool> TaskCheckWinNotification(string notifType, string guest)
{
Windows.UI.Notifications.Management.UserNotificationListener listener = Windows.UI.Notifications.Management.UserNotificationListener.Current;
//only read notifications if we have access - this may need to be set in windows settings
if (listener.GetAccessStatus().ToString() == "Allowed")
{
// Get the windows toast notifications as a list
IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
//Console.Error.WriteLine("number of notifications found: " + notifs.Count());
}
return false;
}
}
}
问题是这条线:
IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
这给出了错误:
'IAsyncOperation<IReadOnlyList<UserNotification>>'
不包含“GetAwaiter”,没有扩展方法的定义“GetAwaiter”接受型'IAsyncOperation<IReadOnlyList<UserNotification>>'
的第一个参数可以找到(是否缺少using指令为“系统”?)
我用尽了一切我可以在网上找到,从添加引用:
要添加的NuGet包:
要重新安装VS和尝试不同版本的SDK。
我真的不知道是什么原因造成这个问题,我会在正确的方向的任何指针非常感谢。
您应该添加
using System.WindowsRuntimeSystemExtensions;
这是来自System.Runtime.WindowsRuntime组件并保持一类与GetAwaiter扩展。