public async void PerformNotifications(object autoEvent) { await semaphoreSlim.WaitAsync(); // working as a lock (){} try { var userNotifications = await listener.GetNotificationsAsync(NotificationKinds.Toast); foreach (UserNotification userNotification in userNotifications) { var waNotification = new WaNotification(userNotification); if (Helpers.IsValid(waNotification)) { var passed = await ProcessNotification(waNotification); if (passed) { listener.RemoveNotification(userNotification.Id); } } } } catch (Exception e) { ConsoleProxy.WriteLine(null, ConsoleColor.DarkRed, e.Message); } finally { semaphoreSlim.Release(); } }
private void NotificationListener_NotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args) { switch (args.ChangeKind) { case UserNotificationChangedKind.Added: UserNotification notification = sender.GetNotification(args.UserNotificationId); if (notification != null && notification.AppInfo.AppUserModelId == WINDOWS_SYSTEM_TOAST_CALLING) { sender.RemoveNotification(notification.Id); } break; } }
private static async Task RemoveNotification(uint notifId) { try { _listener.RemoveNotification(notifId); } catch (Exception) { // ignored } await UpdateNotifications(); }
public void RemoveNotification(uint notifId) { try { _listener.RemoveNotification(notifId); } catch (Exception ex) { ShowMessage(ex.ToString(), "Failed to dismiss notification"); } UpdateNotifications(); }