Task.Delay Method (Int32)
Creates a task that completes after a time delay.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- millisecondsDelay
-
Type:
System.Int32
The number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The millisecondsDelay argument is less than -1. |
The Delay method is typically used to delay the operation of all or part of a task for a specified time interval. Most commonly, the time delay is introduced:
At the beginning of the task, as the following example shows.
Sometime while the task is executing. In this case, the call to the Delay method executes as a child task within a task, as the following example shows. Note that since the task that calls the Delay method executes asynchronously, the parent task must wait for it to complete by using the await keyword.
After the specified time delay, the task is completed in the TaskStatus.RanToCompletion state.
This method depends on the system clock. This means that the time delay will approximately equal the resolution of the system clock if the millisecondsDelay argument is less than the resolution of the system clock, which is approximately 15 milliseconds on Windows systems.
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1