How do I remove tray icon on application uninstall

2019-08-07 02:30发布

问题:

I have an application with tray icon. I am using notifyicon to do this job. I have created its setup in Visual Studio which installs and uninstall the application.

Problem is when I uninstall the program, its tray icon is not removed and even after the program has been uninstalled, I can click on the icon and start the app even though its .exe file from back end has been deleted by the uninstaller.

回答1:

The usual approach is to create in your tray application a background thread which will wait for a named event to be signaled. Then your uninstaller should set this event into the signaled state. When the event is signaled the tray application just exits.

In your tray application's background thread:

EventWaitHandle ev = new EventWaitHandle(false, EventResetMode.AutoReset, "MyCloseEventName");
ev.WaitOne();

In your uninstaller:

EventWaitHandle ev = EventWaitHandle.OpenExisting("MyCloseEventName");
ev.Set();