private void doJob(JobItem item, bool nextSchedule = true) { if (item.Pending == true) { return; } var type = Type.GetType(item.AssemblyQualifiedName); if (type == null) { _jobItems.Remove(item); } else { IJob job = (IJob)type.Assembly.CreateInstance(type.FullName); job.DoJob(); if (nextSchedule) { item.Schedule = job.GetScheduleToNextTurn(item.Schedule); } job.Dispose(); } }
async Task RunJobAsync(IJob job, CancellationToken cancellationToken) { var jobtype = job.GetType() .FullName; job.Log += InvokeLog; job.ExceptionThrown += InvokeExceptionThrown; try { InvokeLog($"\t\tJob {jobtype} {STARTED}"); await job.RunAsync(cancellationToken); } catch (OperationCanceledException) { InvokeLog($"\t\tJob {jobtype} {CANCELLED}"); } catch (Exception exception) { InvokeLog($"\t\tJob {jobtype} {ERRORED}"); InvokeLog($"{jobtype} Exception{NewLine}{exception.ToText()}"); InvokeExceptionThrown(job, new JobExceptionThrownEventArguments { Exception = exception, Job = job }); } finally { job.ExceptionThrown -= InvokeExceptionThrown; job.Log -= InvokeLog; InvokeLog($"\t\tJob {jobtype} {FINISHED}"); job.Dispose(); } }