Solved

C# Winn App System Tray Icon

Posted on 2009-07-07
6
727 Views
Last Modified: 2013-12-17
I have a C# winn app that is running on my system and has the icon in the system tray. If you try to install/repair the app by running the install while the icon is in the system tray I'll get 2 icons in the tray. When I right click on either icon they will bring up the correct form. How can I remove the previously running icon from the tray?
0
Comment
Question by:cholden
6 Comments
 
LVL 4

Expert Comment

by:mysteriousguy
ID: 24800683
Does this happen only when you reinstall your application or on every exit?
Maybe you didn't call Dispose() of the NotifyIcon?
http://www.codeproject.com/KB/cs/trayiconmenu01.aspx
0
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 500 total points
ID: 24800852
You need to exit the application before installing/repairing the application.

For that you can use
foreach ( Process p in System.Diagnostics.Process.GetProcessesByName("yourProcessName") )
{
    try
    {
        p.Kill();
        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
     }
}

0
 
LVL 15

Expert Comment

by:jinal
ID: 24805440
As per Rahu_ketu .

1. Either you can kill previous process by process name.

2. Another way is to create single instance application. So application it self take care of already another process is runnig or not.

C# you have to use Mutex to make application single instance ?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:cholden
ID: 24808418
Rahu_ketu_patal where would I put the code that you suggested?
0
 

Author Comment

by:cholden
ID: 24842548
Thanks for the code Rahu_ketu_patal. I got it to work.

Now I noticed the process has been killed but 2 icons still show in the system tray until the mouse pointer moves over it then one of them disappears. How can I get the icon to be removed for the system tray to avoid this?

Thanks
0
 

Author Comment

by:cholden
ID: 24844316
Nevermind I got it.

Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question