private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.IsTerminating ? "Error:" : "Warning:"); Console.WriteLine(e.ExceptionObject); if (e.IsTerminating) { m_Crashed = true; bool close = false; try { CrashedEventArgs args = new CrashedEventArgs(e.ExceptionObject as Exception); EventSink.InvokeCrashed(args); close = args.Close; } catch { } if (!close && !m_Service) { try { for (int i = 0; i < m_MessagePump.Listeners.Length; i++) { m_MessagePump.Listeners[i].Dispose(); } } catch { } if (m_Service) { Console.WriteLine("This exception is fatal."); } else { Console.WriteLine("This exception is fatal, press return to exit"); Console.ReadLine(); } } EventLog.Error(404, e.ExceptionObject.ToString()); m_Closing = true; } }