Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
- {
- if (tasks == null)
- {
- throw new ArgumentNullException("tasks");
- }
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException("millisecondsTimeout");
- }
- cancellationToken.ThrowIfCancellationRequested();
- List<Exception> innerExceptions = null;
- List<Task> list = null;
- List<Task> list2 = null;
- bool flag = false;
- bool flag2 = false;
- bool flag3 = true;
- for (int i = tasks.Length - 1; i >= 0; i--)
- {
- Task task = tasks[i];
- if (task == null)
- {
- throw new ArgumentException(Environment.GetResourceString("Task_WaitMulti_NullTask"), "tasks");
- }
- bool flag4 = task.IsCompleted;
- if (!flag4)
- {
- if (millisecondsTimeout != -1 || cancellationToken.CanBeCanceled)
- {
- Task item = task;
- int initSize = tasks.Length;
- Task.AddToList<Task>(item, ref list, initSize);
- }
- else
- {
- flag4 = (task.WrappedTryRunInline() && task.IsCompleted);
- if (!flag4)
- {
- Task item2 = task;
- int initSize2 = tasks.Length;
- Task.AddToList<Task>(item2, ref list, initSize2);
- }
- }
- }
- if (flag4)
- {
- if (task.IsFaulted)
- {
- flag = true;
- }
- else
- {
- if (task.IsCanceled)
- {
- flag2 = true;
- }
- }
- if (task.IsWaitNotificationEnabled)
- {
- Task item3 = task;
- int initSize3 = 1;
- Task.AddToList<Task>(item3, ref list2, initSize3);
- }
- }
- }
- if (list != null)
- {
- flag3 = Task.WaitAllBlockingCore(list, millisecondsTimeout, cancellationToken);
- if (flag3)
- {
- foreach (Task current in list)
- {
- if (current.IsFaulted)
- {
- flag = true;
- }
- else
- {
- if (current.IsCanceled)
- {
- flag2 = true;
- }
- }
- if (current.IsWaitNotificationEnabled)
- {
- Task item4 = current;
- int initSize4 = 1;
- Task.AddToList<Task>(item4, ref list2, initSize4);
- }
- }
- }
- GC.KeepAlive(tasks);
- }
- if (flag3 && list2 != null)
- {
- foreach (Task current2 in list2)
- {
- if (current2.NotifyDebuggerOfWaitCompletionIfNecessary())
- {
- break;
- }
- }
- }
- if (flag3 && (flag || flag2))
- {
- if (!flag)
- {
- cancellationToken.ThrowIfCancellationRequested();
- }
- for (int j = 0; j < tasks.Length; j++)
- {
- Task t = tasks[j];
- Task.AddExceptionsForCompletedTask(ref innerExceptions, t);
- }
- throw new AggregateException(innerExceptions);
- }
- return flag3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement