コード例 #1
0
        public static void ScheduleTask(DateTime executeTime)
        {
            SchedulingManager schedulingManager = SchedulingManager.GetManager();

            var existingTask = schedulingManager.GetTaskData().FirstOrDefault(x => x.Key == HashtagSearchScheduledTask.TaskKey);

            if (existingTask == null && usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                // Create a new scheduled task
                HashtagSearchScheduledTask newTask = new HashtagSearchScheduledTask()
                {
                    ExecuteTime = executeTime
                };
                schedulingManager.AddTask(newTask);
            }
            else if (usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                // Updates the existing scheduled task
                existingTask.ExecuteTime = executeTime;
            }
            else
            {
                //Delete the task
                schedulingManager.DeleteItem(existingTask);
            }

            SchedulingManager.RescheduleNextRun();
            schedulingManager.SaveChanges();
        }
コード例 #2
0
        internal static void RemoveScheduledTasks()
        {
            SchedulingManager manager = SchedulingManager.GetManager();

            IList <ScheduledTaskData> scheduledItems = SchedulingManager.GetTasksFromAllProviders(t => t.TaskName == ImageOptimizationTask.GetTaskName());

            foreach (ScheduledTaskData task in scheduledItems)
            {
                manager.DeleteItem(task);
            }

            manager.SaveChanges();
        }