diff ServerMonitor/Program.cs @ 8:052aa62cb42a

Single instance. Add autorun option. Add icons. General enhancements.
author Brad Greco <brad@bgreco.net>
date Sat, 09 Mar 2019 20:14:03 -0500
parents 3e1a2131f897
children 68d7834dc28e
line wrap: on
line diff
--- a/ServerMonitor/Program.cs	Fri Mar 01 21:39:22 2019 -0500
+++ b/ServerMonitor/Program.cs	Sat Mar 09 20:14:03 2019 -0500
@@ -8,19 +8,32 @@
 {
     static class Program
     {
+        static Mutex mutex = new Mutex(true, "c681570e-dff4-45fa-bdca-d8ca928a0f8a");
+
         /// <summary>
         /// The main entry point for the application.
         /// </summary>
         [STAThread]
         static void Main()
         {
-            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
-            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
-            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+            if (mutex.WaitOne(TimeSpan.Zero, true))
+            {
+                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
+                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
 
-            Application.EnableVisualStyles();
-            Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new ServerSummaryForm());
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+                Application.Run(new ServerSummaryForm());
+            }
+            else
+            {
+                Win32Helpers.PostMessage(
+                    (IntPtr)Win32Helpers.HWND_BROADCAST,
+                    Win32Helpers.WM_SHOWMONITOR,
+                    IntPtr.Zero,
+                    IntPtr.Zero);
+            }
         }
 
         static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)