Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Wait Method (Int32)

Task.Wait Method (Int32)

Waits for the Task to complete execution within a specified number of milliseconds.

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

public bool Wait(
	int millisecondsTimeout
)

Parameters

millisecondsTimeout
Type: System.Int32

The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.

Return Value

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

ExceptionCondition
ObjectDisposedException

The Task has been disposed.

ArgumentOutOfRangeException

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

AggregateException

The task was canceled. The AggregateException.InnerExceptions collection contains a TaskCanceledException object.

-or-

An exception was thrown during the execution of the task. The AggregateException.InnerExceptions collection contains information about the exception or exceptions.

Wait(Int32) is a synchronization method that causes the calling thread to wait for the current task instance to complete until one of the following occurs:

  • The task completes successfully.

  • The task itself is canceled or throws an exception. In this case, you handle an AggregateException exception. The AggregateException.InnerExceptions property contains details about the exception or exceptions.

  • The interval defined by millisecondsTimeout elapses. In this case, the current thread resumes execution and the method returns false.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft