protected override IEnumerator Do() { while (!ExitEvent.InterWaitOne(0)) { if (Dispatcher.ProcessNextTask()) { continue; } TaskDistributor.FillTasks(Dispatcher); if (Dispatcher.TaskCount != 0) { continue; } var result = WaitHandle.WaitAny(new[] { ExitEvent, TaskDistributor.NewDataWaitHandle }); if (result == 0) { return(null); } TaskDistributor.FillTasks(Dispatcher); } return(null); }
protected override void OnDestroy() { foreach (var thread in _registeredThreads) { thread.Dispose(); } if (CurrentDispatcher != null) { CurrentDispatcher.Dispose(); } CurrentDispatcher = null; if (CurrentTaskDistributor != null) { CurrentTaskDistributor.Dispose(); } CurrentTaskDistributor = null; base.OnDestroy(); }
public TaskWorker(string name, TaskDistributor taskDistributor) : base(name, false) { TaskDistributor = taskDistributor; Dispatcher = new CustomTaskDispatcher(false); }