diff ServerMonitor/Program.cs @ 17:68d7834dc28e

More comments.
author Brad Greco <brad@bgreco.net>
date Sat, 25 May 2019 15:14:26 -0400
parents 052aa62cb42a
children 7645122aa7a9
line wrap: on
line diff
--- a/ServerMonitor/Program.cs	Tue Apr 30 20:40:58 2019 -0400
+++ b/ServerMonitor/Program.cs	Sat May 25 15:14:26 2019 -0400
@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using System.Threading;
 using System.Windows.Forms;
@@ -16,8 +15,10 @@
         [STAThread]
         static void Main()
         {
+            // Check if the program is already running.
             if (mutex.WaitOne(TimeSpan.Zero, true))
             {
+                // Show unhandled exceptions to the user.
                 Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
@@ -28,6 +29,8 @@
             }
             else
             {
+                // If the program is already running, send a message to the main form
+                // asking it to show itself, then exit.
                 Win32Helpers.PostMessage(
                     (IntPtr)Win32Helpers.HWND_BROADCAST,
                     Win32Helpers.WM_SHOWMONITOR,
@@ -36,18 +39,22 @@
             }
         }
 
+        /// <summary>Shows unhandled exceptions in a message box.</summary>
         static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
         {
-            //if (!System.Diagnostics.Debugger.IsAttached)
+            if (!System.Diagnostics.Debugger.IsAttached)
                 ShowError(e.Exception);
         }
 
+        /// <summary>Shows unhandled exceptions in a message box.</summary>
         static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
         {
-            //if (!System.Diagnostics.Debugger.IsAttached)
+            if (!System.Diagnostics.Debugger.IsAttached)
                 ShowError(e.ExceptionObject as Exception);
         }
 
+        /// <summary>Shows exception details in a message box.</summary>
+        /// <param name="e">The exception to show.</param>
         static void ShowError(Exception e)
         {
             string simpleStackTrace = string.Join(Environment.NewLine, new System.Diagnostics.StackTrace(e).GetFrames()