Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Winn App System Tray Icon

Posted on 2009-07-07
6
Medium Priority
?
742 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 1500 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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