Beispiel #1
0
        public Guid ScheduleTask(Action action, string description, Guid taskId, int delayMilliseconds = 0)
        {
            ThreadTask task = new ThreadTask(taskId);

            task.Description       = description;
            task.TaskToComplete    = action;
            task.DelayMilliseconds = delayMilliseconds;
            ScheduleTask(task);
            return(task.Id);
        }
Beispiel #2
0
 private void CompletedTask(ThreadTask task)
 {
     CompletedTasks.Add(task);
     ActiveTasks.Remove(task);
     if (task.IsError)
     {
         OnErrorTask?.Invoke(this, new ThreadManagerScheduledTaskEventArgs(task));
     }
     else
     {
         OnCompletedTask?.Invoke(this, new ThreadManagerScheduledTaskEventArgs(task));
     }
 }
Beispiel #3
0
        private void RunTask(ThreadTask task)
        {
            task.OnCompletedTask += Task_OnCompletedTask;
            task.OnErrorTask     += Task_OnErrorTask;
            ActiveTasks.Add(task);
            QueuingTasks.Remove(task);
            var thread = new System.Threading.Thread(() =>
            {
                System.Threading.Thread.Sleep(task.DelayMilliseconds);
                task.Run();
            });

            thread.Start();
            OnStartedTask?.Invoke(this, new ThreadManagerScheduledTaskEventArgs(task));
        }
Beispiel #4
0
 private void ScheduleTask(ThreadTask task)
 {
     QueuingTasks.Add(task);
     OnScheduledTask?.Invoke(this, new ThreadManagerScheduledTaskEventArgs(task));
 }