Disposing of Icon when process is killed

cholden used Ask the Experts™
A user installs my app and the app starts and puts a icon in the system tray. If the user tries to install the app again I have a kill process if one is already running. The process is killed but the system tray icon is still there until you move the mouse over it then its gone.

I want the icon to be disposed at the same time the process is being killed in the InstallerClass.cs and removed from the system tray.

How do I go about this?


public override void Install(IDictionary savedState)
            //int x = 0;
            foreach (Process p in System.Diagnostics.Process.GetProcessesByName("DrEckApplication"))
                //if (x > 0)
                        p.WaitForExit(); // possibly with a timeout
                    catch (Win32Exception winException)
                        // process was terminating or can't be terminated - deal with it
                    catch (InvalidOperationException invalidException)
                        // process has already exited - might be able to let this one go

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is a common problem that seems to exist on all Windows applications that have a system tray icon.

To avoid it, you will need to find another way of ending the process before an update, such as communicating with it to close properly.

I believe the simplist way would be for your InstallerClass.cs to perform a TCP/IP connection to the instance already running, asking it to close without being killed. There are probably neater ways to achieve the same thing though...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial