IAsyncOperation >”不包含一个定义为‘GetAwaiter’[重复]

问题描述 投票:2回答:1

我使用Visual Studio 2017年专业。

我一直在关注这个指南:https://docs.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>>'不包含“GetAwaiter”,没有扩展方法的定义“GetAwaiter”接受型'IAsyncOperation<IReadOnlyList<UserNotification>>'的第一个参数可以找到(是否缺少using指令为“系统”?)

我用尽了一切我可以在网上找到,从添加引用:

  • C:\ Program Files文件(x86)的\参考大会\微软\ Framework.NETCore \ V4.5 \ System.Runtime.WindowsRuntime.dll
  • C:\ Program Files文件(x86)的\的Windows套件\ 10 \ UnionMetadata \外观\ Windows.WinMD

要添加的NuGet包:

  • UwpDesktop
  • Microsoft.NETCore.UniversalWindowsPlatform

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

我真的不知道是什么原因造成这个问题,我会在正确的方向的任何指针非常感谢。

c# uwp async-await toast iasyncoperation
1个回答
3
投票

您应该添加

 using System.WindowsRuntimeSystemExtensions;

这是来自System.Runtime.WindowsRuntime组件并保持一类与GetAwaiter扩展。

© www.soinside.com 2019 - 2024. All rights reserved.