gpt4 book ai didi

c# - IAsyncOperation>' does not contain a definition for ' GetAwaiter'

转载 作者:行者123 更新时间:2023-12-03 02:24:00 28 4
gpt4 key购买 nike

我使用的是 Visual Studio 2017 Professional。

我一直在遵循本指南: https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener

我的问题代码如下:

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>>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<IReadOnlyList<UserNotification>>' could be found (are you missing a using directive for 'System'?)

我已经尝试了网上能找到的所有方法,从添加引用到:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
  • C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD

要添加 NuGet 包:

  • Uwp桌面
  • Microsoft.NETCore.UniversalWindowsPlatform

重新安装 VS 并尝试不同版本的 SDK。

我真的不知道是什么导致了这个问题,我将非常感谢任何正确方向的指示。

最佳答案

您应该添加

 using System.WindowsRuntimeSystemExtensions;

它来自 System.Runtime.WindowsRuntime 程序集,并包含一个带有 GetAwaiter 扩展的类。

关于c# - IAsyncOperation<IReadOnlyList<UserNotification>>' does not contain a definition for ' GetAwaiter',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54515716/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com