Line | |
---|
1 | using System;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | using HeuristicLab.Clients.Hive.SlaveCore.Views;
|
---|
5 |
|
---|
6 | namespace 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.