示例#1
0
        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;
                }
            }
        }
示例#2
0
        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);
        }