5

I have a desktop application running in Windows 10 which creates ToastNotifications that are also being stored in the Action Center. I noticed, that when I reboot the computer the Notifications are still present in the Action Center so I wanted to remove them through my Application when they're not necessary anymore.
I wanted to use the ToastNotificationHistory Remove method for this.
My code looks like this:

public static void RemoveNotificationByTag(string toastTag)
{
    ToastNotificationManager.History.Remove(toastTag, "TEST");
}

But this leads to this exception: System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)'

The notification I've been sending priorly has a Tag and a Group value.

I get the same exception when calling the RemoveGroup or GetHistory method. Basically it seems like I cannot call any method from the History class without getting the same exception

sevi
  • 460
  • 5
  • 20
  • 1
    just a suggestion. Try printing all the items in "ToastNotificationManager.History" and check if it contains the toast you need. – Raamakrishnan A. Jun 14 '17 at 12:28
  • Why not just call `Clear()`? _"Removes all notifications sent by this app from action center."_ – stuartd Jun 14 '17 at 12:32
  • I tried to have a look at the History object in the debugger but that just shows: To inspect the native object, enable native code debugging. As soon as I enable it, it says Operation not supported. Calling the Clear method leads to the same exception – sevi Jun 14 '17 at 12:36

1 Answers1

5

On Windows 10 it is necessary to provide the applicationId parameter to each of the methods. Also you must specify not only a toast tag, but its group as well.

Calling the method like this works:

ToastNotificationManager.History.Remove(toastTag, "TEST", appId);
yuyoyuppe
  • 1,582
  • 2
  • 20
  • 33
sevi
  • 460
  • 5
  • 20