private static void Executor_JobDone(object sender, JobDoneEventArg e) { string log = null; string message; switch (e.CurrentJobState) { case JobState.Finished: var executionTime = e.ExecutionTime.HasValue ? $" in {e.ExecutionTime.Value} ms." : "."; log = $"Finished job: {e.JobResult?.MessageToShow ?? string.Empty}, ID: {e.CurrentJobId}"; message = log + executionTime + Environment.NewLine; if (Executor.CanStartNewJob() && !AllJobsHaveFinished()) { Job newJob = PriorityQueue.Dequeue(); Executor.StartJob(newJob); } break; case JobState.Cancelled: message = $"Job: {e.CurrentJobType} (ID: {e.CurrentJobId}) was cancelled by user." + Environment.NewLine; log = $"Canceled job: ID: {e.CurrentJobId}." + Environment.NewLine; if (Executor.CanStartNewJob() && !AllJobsHaveFinished()) { Job newJob = PriorityQueue.Dequeue(); Executor.StartJob(newJob); } break; default: return; } Debug.WriteLine(message); LogHelper.WriteLog(log); }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { time.Stop(); JobResult result = null; if (!e.Cancelled && e.Error == null) { currentJob.Finish(); result = (JobResult)e.Result; } else { currentJob.Cancel(); } JobDoneEventArg jobArg = new JobDoneEventArg(currentJob.Id, currentJob.Type, currentJob.State, result, time.ElapsedMilliseconds); JobDone?.Invoke(sender, jobArg); time.Reset(); }