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); }
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)); }