diff ServerMonitor/Program.cs @ 0:3e1a2131f897

Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
author Brad Greco <brad@bgreco.net>
date Mon, 31 Dec 2018 18:32:14 -0500
parents
children 052aa62cb42a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ServerMonitor/Program.cs	Mon Dec 31 18:32:14 2018 -0500
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace ServerMonitorApp
+{
+    static class Program
+    {
+        /// <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);
+
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new ServerSummaryForm());
+        }
+
+        static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
+        {
+            //if (!System.Diagnostics.Debugger.IsAttached)
+                ShowError(e.Exception);
+        }
+
+        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+        {
+            //if (!System.Diagnostics.Debugger.IsAttached)
+                ShowError(e.ExceptionObject as Exception);
+        }
+
+        static void ShowError(Exception e)
+        {
+            string simpleStackTrace = string.Join(Environment.NewLine, new System.Diagnostics.StackTrace(e).GetFrames()
+                    .Select(f => f.GetMethod().DeclaringType.Name + "." + f.GetMethod().Name).ToArray());
+            MessageBox.Show(e.Message + Environment.NewLine + Environment.NewLine + simpleStackTrace, "Server Monitor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+        }
+    }
+}