public bool AddTask(TaskInfo task) { if (task.NextRunTime == null) { task.NextRunTime = TaskHelper.CalNextRunTime(task); } _tasks[task.TaskId] = task; lock (_runTaskLock) { int removeCount = _needRunTasks.RemoveWhere(f => f.TaskId == task.TaskId); NextRunTask taskStatus = new NextRunTask(); taskStatus.TaskId = task.TaskId; taskStatus.NextRunTime = task.NextRunTime ?? DateTime.Now; _needRunTasks.Add(taskStatus); } return(true); }
public bool AddTasks(IEnumerable <TaskInfo> tasks) { lock (_runTaskLock) { foreach (var task in tasks) { _tasks[task.TaskId] = task; if (task.NextRunTime == null) { task.NextRunTime = TaskHelper.CalNextRunTime(task); } int removeCount = _needRunTasks.RemoveWhere(f => f.TaskId == task.TaskId); NextRunTask taskStatus = new NextRunTask(); taskStatus.TaskId = task.TaskId; taskStatus.NextRunTime = task.NextRunTime ?? DateTime.Now; _needRunTasks.Add(taskStatus); } } return(true); }