3

Visual Studio 2017 Professional を使用しています。

私はこのガイドに従っています: 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>>'が見つかりませんでした ('System' の using ディレクティブがありませんか?)

参照の追加から次への参照の追加から、オンラインで見つけることができるすべてを試しました。

  • 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 を試す。

何がこの問題を引き起こしているのか本当にわかりません。正しい方向への指針に非常に感謝しています。

4

1 に答える 1