Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/Program.cs @ 6110

Last change on this file since 6110 was 5780, checked in by ascheibe, 14 years ago

#1233 worked on installer and slave

File size: 1.4 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Windows.Forms;
4using HeuristicLab.Clients.Hive.SlaveCore.Views;
5
6namespace HeuristicLab.Clients.Hive.SlaveCore.SlaveTrayIcon {
7  static class Program {
8    /// <summary>
9    /// The main entry point for the application.
10    /// </summary>
11    [STAThread]
12    static void Main() {
13      KillOtherInstances();
14
15      Application.EnableVisualStyles();
16      Application.SetCompatibleTextRenderingDefault(false);
17      MainWindow mw = new MainWindow();
18      mw.MinimizeToTray();
19      mw.Content = new SlaveItem();
20
21      Application.Run();
22    }
23
24    /// <summary>
25    /// kill all other slave tray icons, we only want 1 running at a time
26    /// (and if a newer version is installed the older one should be killed)
27    /// </summary>
28    private static void KillOtherInstances() {
29      Process curProc = Process.GetCurrentProcess();
30
31      try {
32        Process[] procs = Process.GetProcessesByName(curProc.ProcessName);
33        foreach (Process p in procs) {
34          if (p.Id != curProc.Id) {
35            p.Kill();
36          }
37        }
38      }
39      catch (InvalidOperationException) {
40      }
41      catch (Exception) {
42        MessageBox.Show("There is another instance of the Hive Slave tray icon running which can't be closed.", "HeuristicLab Hive Slave");
43      }
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.