Пример #1
0
        public static int WaitAny(PoormansTask[] tasks, bool cancelUnfinishedTasks)
        {
            var synchronizer = PoormansSynchronizer.Get();

            int completedTaskIndex = -1;

            while (completedTaskIndex < 0)
            {
                synchronizer.WaitAny();
                completedTaskIndex = Array.FindIndex(tasks, t => t.HasCompleted);
            }

            if (cancelUnfinishedTasks)
            {
                PoormansThreadPool.CancelTasksInternal();
            }

            return(completedTaskIndex);
        }
Пример #2
0
 private void CreateTask(Action action)
 {
     PoormansThreadPool.EnqueueTaskInternal(() =>
     {
         try
         {
             action();
         }
         catch (Exception exception)
         {
             lock (_exceptionMonitor)
                 _exceptions.Add(exception);
         }
         finally
         {
             HasCompleted = true;
             _synchronizer.Signal();
         }
     });
 }
 protected override void QueueTask(Task task)
 {
     PoormansThreadPool.EnqueueTaskInternal(() => base.TryExecuteTask(task));
 }