How to prevent leaving an Icon in System Tray on exit?

Malfist picture Malfist · Oct 26, 2009 · Viewed 13.8k times · Source

My program puts an icon in the system tray because the user may minimize to it. However, if the application crashes, or I stop the app from running in VS it leaves the icon in it until I hover over it with the mouse. Sometimes I'll look down there and there will be 10 or so icons.

I can I make sure the icon goes away?

Answer

JSBձոգչ picture JSBձոգչ · Oct 26, 2009

There is no way to do this. Windows does not poll your program to see if it's still alive. Therefore, your icon will stay in the system tray until you either tell it to leave (normal exit), or the user does something that initiates a call to your program (such as mouseover). Only then does the shell know that your program has died and it needs to clean up your icon.