Tray icon does not disappear on killing process

Lalit picture Lalit · Feb 22, 2010 · Viewed 9.4k times · Source

I have a window service for my application. When i stops that by killing process with task manager, the tray icon does not disappear. Is it a window bug or something else? Do we have a solution for that problem? Thanks in advance :).

Answer

Willem Van Onsem picture Willem Van Onsem · Feb 22, 2010

You can let the icon disappear by calling the Dispose()-method of the specified NotifyIcon-object. In most cases these Container-object isn't part of the tree of components in your application so it will not disappear by killing the proces. When the user moves over the icon, the icon doesn't find it parent so it dissapears. But by calling the Dispose-method, it disapeared at least in my applications. So:

//creating a NotifyIcon
NotifyIcon notifyicon = new NotifyIcon();
notifyicon.Text = "Text"; 
notifyicon.Visible = true; 
notifyicon.Icon = new Icon(GetType(),"Icon.ico");
//let it disappear
notifyicon.Dispose();