NotifyIcon TrayIcon not removed on VS Stop Debugging

1 Answer 28 Views
NotifyIcon
Renier Pretorius
Top achievements
Rank 1
Iron
Renier Pretorius asked on 29 Oct 2021, 05:17 PM

Hi,

When developing my WPF application using the RadNotifyIcon, I often catch myself stopping Visual Studio rather than selecting the close application menu option. This results in the tray icon not being removed. When you then restart a debugging session the old icon prevents a new icon from being created as I have a fixed appId. However, as soon as you hover over it, the icon disappears.

Everything is happening per design and in release mode where you have to close the application, everything works fine. This is just some development time frustration.

Is there a way to check on startup if the icon exists (previous remnant) and if so first clear it before creating the new icon? Alternatively, is there a "fool-proof" way to detect ungraceful application close (e.g. stop debugging in VS) to first clear the icon? 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 03 Nov 2021, 12:42 PM

Hi Renier,

Indeed when the application is terminated forcefully (such as in the case of stopping the debugging operation in Visual Studio), the RemoveIcon method is not called and Windows has no idea that the icon should be removed. This is a known behavior of the Notification Area and is not very intuitive. If the process owning the notify icon no longer exists, hovering over the icon with the mouse would make it disappear, however, as you have come across.

Sadly, there's no fool-proof way to detect when such an ungraceful shutdown occurs.

The only suggestion I have in this case, other than hovering over the icon, is to use a new Guid each time the application is started. That said, please note that with this approach Windows will treat each new start of the app as a new app-notify icon combination and cache it. If you go to Settings->Personalization->Taskbar->Select which icons appear on the taskbar, you will see a long list with duplicates of your application.

I hope you find this information helpful.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
NotifyIcon
Asked by
Renier Pretorius
Top achievements
Rank 1
Iron
Answers by
Dilyan Traykov
Telerik team
Share this question
or