public static void ScheduleTasks() { nextSchedule = SchedulerController.GetNextSchedule(); // set timer if (nextSchedule != null) { if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now) { // this will put the timer to sleep scheduleTimer.Change(Timeout.Infinite, Timeout.Infinite); // run immediately RunNextSchedule(null); } else { // set timer TimeSpan ts = nextSchedule.ScheduleInfo.NextRun.Subtract(DateTime.Now); if (ts < TimeSpan.Zero) { ts = TimeSpan.Zero; // cannot be negative ! } // invoke after the timespan scheduleTimer.Change((long)ts.TotalMilliseconds, Timeout.Infinite); } } }
public static void ScheduleTasks() { RunManualTasks(); nextSchedule = SchedulerController.GetNextSchedule(); if (nextSchedule != null) { if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now) { RunNextSchedule(null); } } }