// Helper function for IsError that gives user the option to respond to the error public static int IsError_WithExitOption(object sender, ErrorInfo error) { if (abort_oven_program) return 1; while (error_window_open) { Thread.Sleep(20); } if (abort_oven_program) return 1; try { USB_TC_Control oven_form = (USB_TC_Control)sender; AbortOvenCode abortcode_del = new AbortOvenCode(oven_form.StopThreads_AndCloseOvenProgram); if (error.Value != 0) { System.Windows.Forms.DialogResult user_resp = DialogResult.None; error_window_open = true; user_resp = MessageBox.Show(error.Message + Environment.NewLine + "Click 'Cancel' to exit out of the oven program", "Error", MessageBoxButtons.OKCancel); if (user_resp == DialogResult.Cancel) { abort_oven_program = true; // Set check flags for the three threads (Oven PID // Control, Read Temp, Log Temp) to -1 to end the // threads oven_check = -1; read_check = -1; log_check = -1; // Pause 100 milliseconds Thread.Sleep(100); // Invoke the close/abort program delegate oven_form.Invoke(abortcode_del); } error_window_open = false; return 1; } } catch { //Call the single argument error handler IsError(error); } return 0; }
// Helper function for IsError that gives user the option to respond to the error public static ErrorCodeEnum IsError_WithExitOption(object sender, ErrorInfo error) { if (abort_oven_program) return ErrorCodeEnum.Error; while (application_error_window_open) { Thread.Sleep(20); } if (abort_oven_program) return ErrorCodeEnum.Error; try { USB_TC_Control_Form oven_form = (USB_TC_Control_Form)sender; AbortOvenCode abortcode_del = new AbortOvenCode(oven_form.StopThreads_AndCloseOvenProgram); if (error.Value != 0) { System.Windows.Forms.DialogResult user_resp = DialogResult.None; application_error_window_open = true; user_resp = MessageBox.Show(error.Message + Environment.NewLine + "Click 'Cancel' to exit out of the oven program", "Error", MessageBoxButtons.OKCancel); if (user_resp == DialogResult.Cancel) { abort_oven_program = true; // Set check flags for the three threads (Oven PID // Control, Read Temp, Log Temp) to -1 to end the // threads oven_check = ComponentCheckStatusEnum.Aborted; read_check = ComponentCheckStatusEnum.Aborted; log_check = ComponentCheckStatusEnum.Aborted; // Pause 100 milliseconds Thread.Sleep(100); // Invoke the close/abort program delegate oven_form.BeginInvoke(abortcode_del); } application_error_window_open = false; return ErrorCodeEnum.Error; } } catch(Exception e) { MessageBox.Show( String.Format( "Unexpected Error occurred while processing Oven Application Error." + "{0}Error Message: {1}{0}" + "Error Source: {2}{0}" + "Stack Trace: {3}{0}", Environment.NewLine, e.Message, e.Source, e.StackTrace), " Unexpected Error!"); //Call the single argument error handler IsError(error); } return ErrorCodeEnum.NoError; }