IAsyncOperation< IReadOnlyList< UserNotification>>"不包含"GetAwaiter"的定义 [英] IAsyncOperation<IReadOnlyList<UserNotification>>' does not contain a definition for 'GetAwaiter'

查看:233
本文介绍了IAsyncOperation< IReadOnlyList< UserNotification>>"不包含"GetAwaiter"的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2017 Professional.

I am using Visual Studio 2017 Professional.

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

I have been following this guide: 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'的定义,找不到可以接受类型为'IAsyncOperation<IReadOnlyList<UserNotification>>'的第一个参数的扩展方法'GetAwaiter'(您是否缺少对'System'的using指令?)

'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'?)

从添加引用到以下内容,我都尝试了所有可以在线找到的内容:

I've tried everything I can find online, from adding references to:

  • 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软件包:

To adding NuGet packages:

  • UwpDesktop
  • Microsoft.NETCore.UniversalWindowsPlatform

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

To reinstalling VS and trying different versions of the SDK.

我真的不知道是什么导致了这个问题,对于任何朝着正确方向的指针,我将不胜感激.

I really have no idea what is causing this issue, I would be very grateful for any pointers in the right direction.

推荐答案

您应该添加

 using System.WindowsRuntimeSystemExtensions;

这是从System.Runtime.WindowsRuntime程序集中获取的,并拥有带有GetAwaiter扩展名的类.

this is from the System.Runtime.WindowsRuntime assembly and holds a class with the GetAwaiter extensions.

这篇关于IAsyncOperation&lt; IReadOnlyList&lt; UserNotification&gt;&gt;"不包含"GetAwaiter"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆