System Tray icon does not disappear RRS feed

  • Question


    I have a C# application and placed its icon in the system tray. I've noticed that whenever the application crashes, the icon stays in the system tray. When I move my mouse over the system tray, however, the icon disappears. Is there a way to make sure that the icon disappears when the application is no longer running? This behavior is getting kinda annoying...
    Friday, July 27, 2007 4:13 PM

All replies


    I know this isn't much help, but I believe that all windows forms have that problem when they crash.  I think that's just an issue with Windows that you can't do much about.  To test this, take any application that loads a system tray icon, then go into the taskmanager and forcefully shutdown that process. The system tray icon will remain until you move the mouse over it.  I can't tell you why this happens.
    Friday, July 27, 2007 4:28 PM
  • I just realized, if you go into taskmgr and end the "taskmgr.exe" process, its own system tray will remain.

    Friday, July 27, 2007 4:31 PM
  • Hey,


    The issue, I believe, is because the cleanup code that handles the cleanup of the icons doesn't run, even though that it may be system code.  Not sure about that, but if you think about that, it may seem the logical reason.


    Something you may want to do is handle this http://msdn2.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx and put code in there to prevent the application from crashing.  Not a guarantee to run, but will help a lot.



    • Proposed as answer by Renee Culver Friday, June 1, 2012 5:58 AM
    Friday, July 27, 2007 4:31 PM
  • The tray icon can stay around, even if your program exits normally.  This is an old bug they say they can't fix for compatibility reasons.  Hmm.  The workaround is to explicitly call NotifyIcon.Hide() in the FormClosing event.  Of course, all bets are off when your program terminates due to an unhandled exception.  Surely, that doesn't happen very often to be annoying?
    Friday, July 27, 2007 4:53 PM
  • What I found to be annoying is that whenever I run the uninstaller (using Setup and Deployment project) the application icon is still present in the system tray. Is there a way to refresh the system tray during the uninstall event?

    Friday, July 27, 2007 5:46 PM
  • Not sure I understand.  Do you abort a running instance of the program when you uninstall it?
    Friday, July 27, 2007 6:55 PM
  • Yes. Our users are allowed to uninstall even while the application is running. I call Process.Kill. The application then closes during the uninstallation but the icon is still in the system tray.

    Monday, July 30, 2007 11:10 PM
  • Egad, don't kill it then.  I'll move on to a real question now...
    Monday, July 30, 2007 11:37 PM
  • You don't seem to understand. The question the person is asking is, why the icon remains in the system tray after the application crashes. He's not looking for a recommendation to "don't kill an application". 

    He simply wants to know why this happens. And it's something I want fixed as well.

    I want that when an application crashes, or if I kill it manually from the Task Manager, that the icon immediately disappears. I don't want those icons to remain there.

    "Don't kill it then" is not the answer. The answer is to fix this behavior.

    Thursday, September 12, 2013 1:07 PM
  • I have the same question.

    I show an notifyicon when my app starts, with version number etc. After I close my C#, WinForm application normally, and the notifyicon have gone through its closing method, the "icon" is still in Windows 10 system tray. Or more like an "empty" icon, that takes up space.

    I see its many that asks the same question, with small variations. have anyone found a workaround?

    • Edited by MrBjornH Tuesday, May 14, 2019 1:38 PM
    Tuesday, May 14, 2019 1:37 PM