示例#1
0
 protected virtual void InvokeCallback(object state)
 {
     try
     {
         ISchedulerItem item = (ISchedulerItem)state;
         item.Invoke();
     }
     catch (Exception x)
     {
         Logger.Error(x, "Error while executing schedule item.");
     }
 }
示例#2
0
        protected virtual void ExecuteItemCallback(object state, bool timedOut)
        {
            try
            {
                ISchedulerItem item;
                bool           execute;
                lock (schedulerQueue)
                {
                    executeHandle.Unregister(executeEvent);
                    executeEvent.Close();
                    executeHandle = null;

                    item = schedulerQueue.Top();
                    if (item == null)
                    {
                        return;
                    }

                    DateTime now = DateTime.UtcNow;
                    execute = now >= item.NextStart.ToUniversalTime();
                    if (execute)
                    {
                        item.Increase();
                    }

                    ISchedulerItem top = schedulerQueue.Top();
                    if (top != null)
                    {
                        TimeSpan interval = new TimeSpan(0, 0, 1);
                        DateTime next     = top.NextStart.ToUniversalTime();
                        if (next > now)
                        {
                            interval = next - now;
                            Logger.Debug("Next event at {0:u}.", top.NextStart.ToLocalTime());
                        }

                        executeEvent  = new AutoResetEvent(false);
                        executeHandle = ThreadPool.RegisterWaitForSingleObject(executeEvent, ExecuteItemCallback, null, interval, true);
                    }
                }

                if (execute)
                {
                    Logger.Debug("Starting scheduled item '{0}'.", item.Name);
                    ThreadPool.QueueUserWorkItem(InvokeCallback, item);
                }
            }
            catch (Exception x)
            {
                Logger.Error(x, "Error while processing schedule. Scheduler is halting.");
            }
        }
 public ScheduleItemStatus(ISchedulerItem item)
 {
     Name      = item.Name;
     NextStart = item.NextStart;
     LastStart = item.LastStart;
 }