/// <summary> /// Queues the scheduled task. /// </summary> /// <typeparam name="T"></typeparam> public void QueueScheduledTask <T>() where T : IScheduledTask { var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); QueueScheduledTask(scheduledTask); }
/// <summary> /// Executes the queued tasks. /// </summary> private void ExecuteQueuedTasks() { Logger.LogInformation("ExecuteQueuedTasks"); // Execute queued tasks lock (_taskQueue) { var list = new List <Tuple <Type, TaskOptions> >(); while (_taskQueue.TryDequeue(out var item)) { if (list.All(i => i.Item1 != item.Item1)) { list.Add(item); } } foreach (var enqueuedType in list) { var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == enqueuedType.Item1); if (scheduledTask.State == TaskState.Idle) { Execute(scheduledTask, enqueuedType.Item2); } } } }
/// <summary> /// Cancels if running /// </summary> /// <typeparam name="T"></typeparam> public void CancelIfRunning <T>() where T : IScheduledTask { var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); ((ScheduledTaskWorker)task).CancelIfRunning(); }
/// <summary> /// Queues the scheduled task. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="options">Task options</param> public void QueueScheduledTask <T>(TaskExecutionOptions options) where T : IScheduledTask { var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); QueueScheduledTask(scheduledTask, options); }
/// <summary> /// Cancels if running and queue. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="options">Task options.</param> public void CancelIfRunningAndQueue <T>(TaskOptions options) where T : IScheduledTask { var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); ((ScheduledTaskWorker)task).CancelIfRunning(); QueueScheduledTask <T>(options); }
public void QueueIfNotRunning <T>() where T : IScheduledTask { var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); if (task.State != TaskState.Running) { QueueScheduledTask <T>(new TaskOptions()); } }
/// <summary> /// Executes the queued tasks. /// </summary> private void ExecuteQueuedTasks() { // Execute queued tasks lock (_taskQueue) { foreach (var type in _taskQueue.ToList()) { var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == type); if (scheduledTask.State == TaskState.Idle) { Execute(scheduledTask); _taskQueue.Remove(type); } } } }
/// <summary> /// Queues the scheduled task. /// </summary> /// <param name="task">The task.</param> public void QueueScheduledTask(IScheduledTask task) { var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == task.GetType()); QueueScheduledTask(scheduledTask); }
/// <summary> /// Queues the scheduled task. /// </summary> /// <param name="task">The task.</param> /// <param name="options">The task options.</param> public void QueueScheduledTask(IScheduledTask task, TaskExecutionOptions options) { var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == task.GetType()); QueueScheduledTask(scheduledTask, options); }