Delay Method (Int32)
Collapse the table of content
Expand the table of content

Task.Delay Method (Int32)

.NET Framework (current version)
 

Creates a task that completes after a time delay.

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

static member Delay : 
        millisecondsDelay:int -> Task

Parameters

millisecondsDelay
Type: System.Int32

The number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.

Return Value

Type: System.Threading.Tasks.Task

A task that represents the time delay.

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.

    No code example is currently available or this language may not be supported.
  • 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.

    No code example is currently available or this language may not be supported.

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.

The following example shows a simple use of the Delay method.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 4.5
.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
Return to top
Show:
© 2016 Microsoft