I'm trying to code a form for show notifications in my form from Notification Center but there is some error I did not understand errors.
Errors:
*Severity Code Description Project File Line Suppression State
Error CS4036 'IAsyncOperation<UserNotificationListenerAccessStatus>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<UserNotificationListenerAccessStatus>' could be found (are you missing a using directive for 'System'?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Class1.cs 12 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationListener' does not contain a definition for 'GetNotifications' and no accessible extension method 'GetNotifications' accepting a first argument of type 'UserNotificationListener' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Class1.cs 17 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationChangedEventArgs' does not contain a definition for 'Notification' and no accessible extension method 'Notification' accepting a first argument of type 'UserNotificationChangedEventArgs' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Class1.cs 33 Active
*
*Severity Code Description Project File Line Suppression State
Error CS4036 'IAsyncOperation<UserNotificationListenerAccessStatus>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<UserNotificationListenerAccessStatus>' could be found (are you missing a using directive for 'System'?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Form2.cs 29 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationListener' does not contain a definition for 'GetNotifications' and no accessible extension method 'GetNotifications' accepting a first argument of type 'UserNotificationListener' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Form2.cs 34 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationChangedEventArgs' does not contain a definition for 'Notification' and no accessible extension method 'Notification' accepting a first argument of type 'UserNotificationChangedEventArgs' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Form2.cs 50 Active
*
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.UI.Notifications;
using Windows.UI.Notifications.Management;
namespace WindowsFormsApp7
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public async Task StartListeningAsync()
{
// Request access to the user's notifications
var accessStatus = await UserNotificationListener.Current.RequestAccessAsync();
if (accessStatus == UserNotificationListenerAccessStatus.Allowed)
{
// Get the user's notifications
var notifications = UserNotificationListener.Current.GetNotifications(NotificationKinds.Toast);
foreach (var notification in notifications)
{
// Process the notification
ProcessNotification(notification);
}
// Register for notifications when they are updated
UserNotificationListener.Current.NotificationChanged += OnNotificationChanged;
}
}
private void OnNotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args)
{
// Process the updated notification
ProcessNotification(args.Notification);
}
private void ProcessNotification(UserNotification notification)
{
// Do something with the notification
}
}
}