Example #1
0
        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();
        }
Example #2
0
        public static void StartSchedule(SchedulerJob schedule)
        {
            Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();

            if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
            {
                return;
            }

            // run schedule
            RunSchedule(schedule, false);
        }
Example #3
0
        public static void StopSchedule(SchedulerJob schedule)
        {
            Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();

            if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
            {
                return;
            }

            BackgroundTask activeTask = scheduledTasks[schedule.ScheduleInfo.ScheduleId];

            TaskManager.StopTask(activeTask.TaskId);
        }
Example #4
0
        public static bool IsScheduleActive(int scheduleId)
        {
            Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();

            return(scheduledTasks.ContainsKey(scheduleId));
        }
Example #5
0
        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)
                {
                }
            }
        }