Task.WaitAll Method (Task[], TimeSpan)

Waits for all of the provided cancellable Task objects to complete execution within a specified time interval.

Namespace:  System.Threading.Tasks
Assemblies:   System.Threading.Tasks (in System.Threading.Tasks.dll)
  mscorlib (in mscorlib.dll)

public static bool WaitAll(
	Task[] tasks,
	TimeSpan timeout
)

Parameters

tasks
Type: System.Threading.Tasks.Task[]

An array of Task instances on which to wait.

timeout
Type: System.TimeSpan

A TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.

Return Value

Type: System.Boolean
true if all of the Task instances completed execution within the allotted time; otherwise, false.

ExceptionCondition
ObjectDisposedException

One or more of the Task objects in tasks has been disposed.

ArgumentNullException

The tasks argument is null.

AggregateException

At least one of the Task instances was canceled. If a task was canceled, the AggregateException contains an OperationCanceledException in its InnerExceptions collection.

-or-

An exception was thrown during the execution of at least one of the Task instances.

ArgumentOutOfRangeException

timeout is a negative number other than -1 milliseconds, which represents an infinite time-out.

-or-

timeout is greater than MaxValue.

ArgumentException

The tasks argument contains a null element.

The cancellationToken argument is used to cancel the wait operation. If it is canceled, the Wait returns false (False in Visual Basic). Cancellation of the tasks is a distinct operation, and is signaled by the AggregateException as noted above.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft