/// <summary> /// Invoked when a BackgroundWorker begins working. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BgWorkerDoWork(object sender, DoWorkEventArgs e) { var rowData = e.Argument as GridRow; e.Result = rowData; _runningCount++; ProgramHelper.DoWork(rowData); }
private void ParseLog(object logFile) { var row = new GridRow(logFile as string, "Ready to parse") { BgWorker = new System.ComponentModel.BackgroundWorker() { WorkerReportsProgress = true } }; try { ProgramHelper.DoWork(row); } catch (CancellationException ex) { Console.WriteLine(ex.InnerException != null ? ex.InnerException.Message : ex.Message); } catch (Exception) { Console.WriteLine("Something terrible has happened"); } }
private static void ParseLog(string logFile) { var operation = new ConsoleOperationController(logFile); try { ProgramHelper.DoWork(operation); operation.FinalizeStatus("Parsing Successful - "); } catch (ProgramException ex) { operation.UpdateProgress(ex.InnerException.Message); operation.FinalizeStatus("Parsing Failure - "); } catch (Exception) { operation.UpdateProgress("Something terrible has happened"); operation.FinalizeStatus("Parsing Failure - "); } finally { ProgramHelper.GenerateTraceFile(operation); } }
private void ParseLog(string logFile) { var operation = new ConsoleOperationController(logFile, "Ready to parse"); try { ProgramHelper.DoWork(operation); operation.FinalizeStatus("Parsing Successful - "); } catch (ExceptionEncompass ex) { operation.UpdateProgress(ex.GetFinalException().Message); operation.FinalizeStatus("Parsing Failure - "); } catch (Exception) { operation.UpdateProgress("Something terrible has happened"); operation.FinalizeStatus("Parsing Failure - "); } finally { ProgramHelper.GenerateLogFile(operation); } }
private void _RunOperation(FormOperationController operation) { _runningCount++; _settingsForm.ConditionalSettingDisable(_anyRunning); operation.ToQueuedState(); var cancelTokenSource = new CancellationTokenSource();// Prepare task Task task = Task.Run(() => { operation.ToRunState(); ProgramHelper.DoWork(operation); }, cancelTokenSource.Token).ContinueWith(t => { cancelTokenSource.Dispose(); _runningCount--; // Exception management if (t.IsFaulted) { if (t.Exception != null) { if (t.Exception.InnerExceptions.Count > 1) { operation.UpdateProgress("Something terrible has happened"); } else { Exception ex = t.Exception.InnerExceptions[0]; if (!(ex is EncompassException)) { operation.UpdateProgress("Something terrible has happened"); } if (!(ex.InnerException is OperationCanceledException)) { operation.UpdateProgress(ex.GetFinalException().Message); } else { operation.UpdateProgress("Operation Aborted"); } } } else { operation.UpdateProgress("Something terrible has happened"); } } if (operation.State == OperationState.ClearOnCancel) { operatorBindingSource.Remove(operation); } else { if (t.IsFaulted) { operation.ToUnCompleteState(); } else if (t.IsCanceled) { operation.UpdateProgress("Operation Aborted"); operation.ToUnCompleteState(); } else if (t.IsCompleted) { operation.ToCompleteState(); } else { operation.UpdateProgress("Something terrible has happened"); operation.ToUnCompleteState(); } } ProgramHelper.GenerateTraceFile(operation); RunNextOperation(); }, TaskScheduler.FromCurrentSynchronizationContext()); operation.SetContext(cancelTokenSource, task); }