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(); }
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(); }