private static void ContinueWith(Task task) { task.ContinueWith(t => { PerfomedTasks.Remove(t.Id); var newKeyValuePair = LazyTasks.FirstOrDefault(); var newTask = newKeyValuePair.Value; if (newTask != null) { LazyTasks.Remove(newTask.Id); PerfomedTasks.Add(newTask.Id, newTask); newTask.Start(); System.Diagnostics.Debug.WriteLine(string.Format("Start task in ContinueWith: {0}", newTask.Id)); } }); }
public static bool AddTask(Task task) { int perfomedTasksCount = PerfomedTasks.Count; int queueTasksCount = LazyTasks.Count; if (perfomedTasksCount < PERFOM_CAPACITTY) { PerfomedTasks.Add(task.Id, task); ContinueWith(task); task.Start(); System.Diagnostics.Debug.WriteLine(string.Format("Start task in performed: {0}", task.Id)); return(true); } else if (queueTasksCount < QUEUE_CAPACITTY) { LazyTasks.Add(task.Id, task); ContinueWith(task); return(true); } return(false); }