如何在C#中卸载应用程序时删除托盘图标 [英] How do I remove tray icon on application uninstall in C#
问题描述
我有一个带有任务栏图标的应用程序.我正在使用notifyicon来完成这项工作. 我已经在安装和卸载该应用程序的Visual Studio中创建了它的安装程序.
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.
问题是当我卸载程序时,它的托盘图标没有被删除,即使卸载了程序,即使从后端删除了其.exe文件,我也可以单击该图标并启动该应用程序.卸载程序.
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.
推荐答案
通常的方法是在任务栏应用程序中创建一个后台线程,该线程将等待信号通知命名事件.然后,您的卸载程序应将此事件设置为信号状态.信号通知事件后,托盘应用程序即退出.
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();
在卸载程序中:
EventWaitHandle ev = EventWaitHandle.OpenExisting("MyCloseEventName");
ev.Set();
这篇关于如何在C#中卸载应用程序时删除托盘图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!