comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:3e1a2131f897
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Threading;
5 using System.Windows.Forms;
6
7 namespace ServerMonitorApp
8 {
9 static class Program
10 {
11 /// <summary>
12 /// The main entry point for the application.
13 /// </summary>
14 [STAThread]
15 static void Main()
16 {
17 Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
18 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
19 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
20
21 Application.EnableVisualStyles();
22 Application.SetCompatibleTextRenderingDefault(false);
23 Application.Run(new ServerSummaryForm());
24 }
25
26 static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
27 {
28 //if (!System.Diagnostics.Debugger.IsAttached)
29 ShowError(e.Exception);
30 }
31
32 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
33 {
34 //if (!System.Diagnostics.Debugger.IsAttached)
35 ShowError(e.ExceptionObject as Exception);
36 }
37
38 static void ShowError(Exception e)
39 {
40 string simpleStackTrace = string.Join(Environment.NewLine, new System.Diagnostics.StackTrace(e).GetFrames()
41 .Select(f => f.GetMethod().DeclaringType.Name + "." + f.GetMethod().Name).ToArray());
42 MessageBox.Show(e.Message + Environment.NewLine + Environment.NewLine + simpleStackTrace, "Server Monitor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
43 }
44 }
45 }