using System; using System.Diagnostics; using System.Windows.Forms; using HeuristicLab.Clients.Hive.SlaveCore.Views; namespace HeuristicLab.Clients.Hive.SlaveCore.SlaveTrayIcon { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { KillOtherInstances(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainWindow mw = new MainWindow(); mw.MinimizeToTray(); mw.Content = new SlaveItem(); Application.Run(); } /// /// kill all other slave tray icons, we only want 1 running at a time /// (and if a newer version is installed the older one should be killed) /// private static void KillOtherInstances() { Process curProc = Process.GetCurrentProcess(); try { Process[] procs = Process.GetProcessesByName(curProc.ProcessName); foreach (Process p in procs) { if (p.Id != curProc.Id) { p.Kill(); } } } catch (InvalidOperationException) { } catch (Exception) { MessageBox.Show("There is another instance of the Hive Slave tray icon running which can't be closed.", "HeuristicLab Hive Slave"); } } } }