Solved

C# Winn App System Tray Icon

Posted on 2009-07-07
6
714 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 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now