Example #1
0
        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);
        }
Example #2
0
        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);
        }