Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
 public TaskWorker(string name, TaskDistributor taskDistributor)
     : base(name, false)
 {
     TaskDistributor = taskDistributor;
     Dispatcher      = new CustomTaskDispatcher(false);
 }