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)); }
public void Run() { StartedOn = DateTime.Now; OnStartedTask?.Invoke(this, new ThreadTaskEventArgs()); try { TaskToComplete.Invoke(); } catch (Exception e) { IsError = true; Exception = e; OnErrorTask?.Invoke(this, new ThreadTaskEventArgs(e)); } CompletedOn = DateTime.Now; OnCompletedTask?.Invoke(this, new ThreadTaskEventArgs()); }