Task::Wait Method (Int32)
Waits for the Task to complete execution within a specified number of milliseconds.
Assembly: mscorlib (in mscorlib.dll)
The Task has been disposed.
millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.
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.
The following example starts a task that generates five million random integers between 0 and 100 and computes their mean. The example uses themethod to wait for the application to complete within 150 milliseconds. If the application completes normally, the task displays the sum and mean of the random numbers that it has generated. If the timeout interval has elapsed, the example displays a message before it terminates.
Available since 8
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 5.0
Windows Phone Silverlight
Available since 8.0
Available since 8.1