How do I remove tray icon on application uninstall in C#

只愿长相守 提交于 2019-12-11 08:25:33

问题


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();


来源:https://stackoverflow.com/questions/10360959/how-do-i-remove-tray-icon-on-application-uninstall-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!