Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

C# Winn App System Tray Icon

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
cholden
Asked:
cholden
1 Solution
 
mysteriousguyCommented:
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
 
Rahul Goel ITILSenior Consultant - DeloitteCommented:
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
 
jinalCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
choldenAuthor Commented:
Rahu_ketu_patal where would I put the code that you suggested?
0
 
choldenAuthor Commented:
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
 
choldenAuthor Commented:
Nevermind I got it.

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now