Mercurial > servermonitor
view ServerMonitor/Program.cs @ 40:c4fc74593a78 default tip
Mono fix
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sat, 13 Jun 2020 13:28:20 -0400 |
parents | 7645122aa7a9 |
children |
line wrap: on
line source
using System; using System.Linq; using System.Threading; using System.Windows.Forms; namespace ServerMonitorApp { 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() { // 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); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ServerSummaryForm()); } 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, IntPtr.Zero, IntPtr.Zero); } } /// <summary>Shows unhandled exceptions in a message box.</summary> static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { 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) 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 = Helpers.IsMono() ? e.ToString() : 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); } } }