Task.Wait Method ()
Waits for the Task to complete execution.
Assembly: mscorlib (in mscorlib.dll)
The Task has been disposed.
Wait is a synchronization method that causes the calling thread to wait until the current task has completed. If the current task has not started execution, the Wait method attempts to remove the task from the scheduler and execute it inline on the current thread. If it is unable to do that, or if the current task has already started execution, it blocks the calling thread until the task completes. For more information, see Task.Wait and "Inlining" in the Parallel Programming with .NET blog.
For more information and an example, see How to: Wait on One or More Tasks to Complete.
The following example starts a task that generates one million random integers between 0 and 100 and computes their mean. The example uses themethod to ensure that the task completes before the application terminates. Otherwise, because this is a console application, the example would terminate before the task can compute and display the mean.
Available since 4.5
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