public void RunTasks(float time) { currentTime = time; while (pendingTaskGroups.Count > 0 || runningTaskGroups.Count > 0) { for (int groupIndex = pendingTaskGroups.Count - 1; groupIndex >= 0; --groupIndex) { if (pendingTaskGroups[groupIndex].CanBeQueued()) { ThreadTaskGroup taskGroup = pendingTaskGroups[groupIndex]; runningTaskGroups.Add(taskGroup); pendingTaskGroups.RemoveAt(groupIndex); foreach (ThreadTask task in taskGroup.Tasks) { ThreadPool.QueueUserWorkItem(task.Callback, time); } Thread.Yield(); } } for (int runningGroupIndex = runningTaskGroups.Count - 1; runningGroupIndex >= 0; --runningGroupIndex) { if (runningTaskGroups[runningGroupIndex].IsDone()) { completedTaskGroups.Add(runningTaskGroups[runningGroupIndex]); runningTaskGroups.RemoveAt(runningGroupIndex); } } Thread.Yield(); } }
public void AddDependency(ThreadTaskGroup group) { dependencies.Add(group); }
public void AddGroup(ThreadTaskGroup group) { pendingTaskGroups.Add(group); }