Solved

C# Winn App System Tray Icon

Posted on 2009-07-07
6
734 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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