C# IAsyncOperation<;IReadOnlyList<;用户通知>&燃气轮机';不包含';GetWaiter';

C# IAsyncOperation<;IReadOnlyList<;用户通知>&燃气轮机';不包含';GetWaiter';,c#,uwp,async-await,toast,iasyncoperation,C#,Uwp,Async Await,Toast,Iasyncoperation,我正在使用Visual Studio 2017 Professional 我一直遵循这一指南: 我的问题代码如下: using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Windows.UI.Notifications; using System; namespace Selenium

我正在使用Visual Studio 2017 Professional

我一直遵循这一指南:

我的问题代码如下:

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;
        }
    }
}
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统线程;
使用System.Threading.Tasks;
使用Windows.UI.Notifications;
使用制度;
命名空间SeleniumWebChat.Utilities
{
//此类处理接收到新webchat/呼叫时弹出的Windows“Toast”通知
静态类WinNotificationHandler
{
静态异步任务TaskCheckWinNotification(字符串notifType,字符串guest)
{
Windows.UI.Notifications.Management.UserNotificationListener侦听器=Windows.UI.Notifications.Management.UserNotificationListener.Current;
//只有在我们有访问权限时才读取通知-这可能需要在windows设置中设置
if(listener.GetAccessStatus().ToString()=“允许”)
{
//以列表形式获取windows toast通知
IReadOnlyList notifs=wait listener.GetNotificationsAsync(NotificationKinds.Toast);
//Console.Error.WriteLine(“找到的通知数:+notifs.Count());
}
返回false;
}
}
}
这一行的问题在于:

IReadOnlyList notifs=wait listener.GetNotificationsAsync(NotificationKinds.Toast);
这就产生了错误:

'IAsyncOperation'
不包含'GetAwaiter'的定义,并且找不到接受类型为
'IAsyncOperation'
的第一个参数的扩展方法'GetAwaiter'(是否缺少'System'的using指令?)

我已经尝试了我能在网上找到的一切,从添加引用到:

  • C:\Program Files(x86)\Reference Assembly\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
  • C:\ProgramFiles(x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD
要添加NuGet软件包,请执行以下操作:

  • UwpDesktop
  • Microsoft.NETCore.UniversalWindowsPlatform
重新安装VS并尝试不同版本的SDK

我真的不知道是什么导致了这个问题,如果有任何指向正确方向的指示,我将不胜感激。

您应该补充

 using System.WindowsRuntimeSystemExtensions;

这是来自System.Runtime.WindowsRuntime程序集的,它包含一个带有GetWaiter扩展名的类。

from:,“.NET具有AsTask扩展方法”,因此。。。如果要使用
等待
,请尝试使用
.AsTask()
?-不知道这是否有帮助如果没有帮助,请确切告诉我们您正在制作什么样的应用程序(哪个UWP模板等)。更好的是,写一封信。看起来你做得很对。请尝试重建项目,并将鼠标悬停在Visual Studio中的
GetNotificationsAsync
上,告诉我intellisense返回的是什么。这不是问题所在,但最好将枚举与枚举值进行比较,而不是使用字符串
listener.GetAccessStatus()==UserNotificationListenerAccessStatus.Allowed
@MichaelPuckettII-它给出与上面相同的错误-“IAsyncOperation”不包含“GetAwaiter”的定义,并且找不到接受“IAsyncOperation”类型的第一个参数的扩展方法“GetAwaiter”(您是否缺少“系统”的using指令?)谢谢!如果有人想知道,我是从C:\Program Files(x86)\Reference Assemblys\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll添加此程序集的