protected virtual void RunPendingJobs() { var now = SchedulingTimeHelpers.Now(); var dueJobs = new List <SchedulingItemContext>(); SchedulingItemContext currentJob = null; for (int i = 0; i < SchedulingItems.Count; i++) { var job = SchedulingItems[i]; if (job.NextExecution.Value > now) { break; } dueJobs.Add(job); } try { for (var i = dueJobs.Count - 1; i >= 0; i--) { currentJob = dueJobs[i]; currentJob.ExecuteAsync(this); if (currentJob.NextExecution.HasValue) { IsSorted = false; } else { SchedulingItems.RemoveAt(i); } } } catch (Exception e) { if (!SubmitJobException(currentJob.ManagedJob, e)) { throw; } } }
public virtual bool Cancel(string id) { lock (SyncRoot) { for (int i = 0; i < SchedulingItems.Count; i++) { var job = SchedulingItems[i]; if (job.ManagedJob.Id == id) { SchedulingItems.RemoveAt(i); job.ManagedJob.Cancel(); if (i == 0) { Reschedule(); } return(true); } } } return(false); }