static void RunSchedule(SchedulerJob schedule, bool changeNextRun) { // update next run (if required) if (changeNextRun) { SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo); } // disable run once task if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime) { schedule.ScheduleInfo.Enabled = false; } Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks(); if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { // this task should be run, so // update its last run schedule.ScheduleInfo.LastRun = DateTime.Now; } // update schedule SchedulerController.UpdateSchedule(schedule.ScheduleInfo); // skip execution if the current task is still running if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { return; } // run the schedule in the separate thread schedule.Run(); }
public int UpdateSchedule(ScheduleInfo schedule) { return(SchedulerController.UpdateSchedule(schedule)); }
static void RunSchedule(SchedulerJob schedule, bool changeNextRun) { try { // update next run (if required) if (changeNextRun) { SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo); } // disable run once task if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime) { schedule.ScheduleInfo.Enabled = false; } Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks(); if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { // this task should be run, so // update its last run schedule.ScheduleInfo.LastRun = DateTime.Now; } // update schedule int MAX_RETRY_COUNT = 10; int counter = 0; while (counter < MAX_RETRY_COUNT) { try { SchedulerController.UpdateSchedule(schedule.ScheduleInfo); break; } catch (SqlException) { System.Threading.Thread.Sleep(1000); } counter++; } if (counter == MAX_RETRY_COUNT) { return; } // skip execution if the current task is still running scheduledTasks = TaskManager.GetScheduledTasks(); if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId)) { // run the schedule in the separate thread schedule.Run(); } } catch (Exception Ex) { try { TaskManager.WriteError(string.Format("RunSchedule Error : {0}", Ex.Message)); } catch (Exception) { } } }