//------------------------------------------------------------------------------------------------------ //private static void Application_ThreadException( // object sender, // System.Threading.ThreadExceptionEventArgs e) //{ // try // { // MessageBox.Show( // String.Format("Произошел сбой работы приложения. Ошибка: {0}. Стек: {1}", // e.Exception.Message, e.Exception.StackTrace), // "Ошибка", MessageBoxButtons.OK); // Application.Exit(); // } // catch // { // try // { // MessageBox.Show("Fatal Windows Forms Error", // "Fatal Windows Forms Error", // MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop); // } // finally // { // Application.Exit(); // } // } //} //------------------------------------------------------------------------------------------------------ // Handle the UI exceptions by showing a dialog box, and asking the user whether // or not they wish to abort execution. // NOTE: This exception cannot be kept from terminating the application - it can only // log the event, and inform the user about it. private static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e) { try { Exception ex = (Exception)e.ExceptionObject; String dumpName; DumpMaker.CreateMiniDump(Application.StartupPath, DUMP_TYPE.MiniDumpNormal, out dumpName); string errorMsg = "An application error occurred. Please contact the adminstrator " + "with the following information:\n\n" + ex.Message + "\n\nStack Trace:\n" + ex.StackTrace + "This application made a dump in directory: " + Application.StartupPath + @"\" + dumpName; //// Since we can't prevent the app from terminating, log this to the event log. if (!EventLog.SourceExists(Application.ProductName)) { EventLog.CreateEventSource(Application.ProductName, "Application"); } //// Create an EventLog instance and assign its source. EventLog myLog = new EventLog("Application", System.Environment.MachineName); myLog.Source = Application.ProductName; myLog.WriteEntry(errorMsg, EventLogEntryType.Error); // Записываем в журнал событий //_Trace.TraceEvent(TraceEventType.Error, 1, ex.StackTrace); //_Trace.Flush(); //MessageBox.Show(errorMsg + String.Format("Error: {0}. StackTrace: {1}", // ex.Message, ex.StackTrace), // "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } catch (Exception exc) { try { MessageBox.Show("Fatal Non-UI Error", "Fatal Non-UI Error. Could not write the error to the event log. Reason: " + exc.Message, MessageBoxButtons.OK, MessageBoxIcon.Stop); } finally { Application.Exit(); } } }
/// <summary> /// Функция потока. /// Отдельная функция сделана для того, чтобы в неё можно было передать "out AutoResetEvent hFinishedSearchEvent" /// </summary> /// <param name="Parameter"></param> private static void ShowAsyncThreadFunc(object Parameter) { CShowAsyncParam ThreadParam = Parameter as CShowAsyncParam; CWaitingWnd wnd = new CWaitingWnd(ThreadParam.m_ID, ThreadParam.m_hFinishedSearchEvent, ThreadParam.m_OwnerWindow, ThreadParam.m_WndText, ThreadParam.m_WndTitle, 300); try { m_dictAllWnds.TryAddValue(ThreadParam.m_ID, wnd); wnd.ShowDialog(); } catch (Exception ex) { DumpMaker.HandleExceptionAndClose(ex, AppAttributes.Title); } }