コード例 #1
0
        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();
            }
        }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
        private static async Task RemoveNotification(uint notifId)
        {
            try
            {
                _listener.RemoveNotification(notifId);
            }

            catch (Exception)
            {
                // ignored
            }

            await UpdateNotifications();
        }
コード例 #4
0
        public void RemoveNotification(uint notifId)
        {
            try
            {
                _listener.RemoveNotification(notifId);
            }

            catch (Exception ex)
            {
                ShowMessage(ex.ToString(), "Failed to dismiss notification");
            }

            UpdateNotifications();
        }