System.Threading.Thread.Sleep Method

Suspends the current thread for the specified amount of time.

Syntax

public static void Sleep (TimeSpan timeout)

Parameters

timeout
The amount of time for which the thread is suspended.

Exceptions

TypeReason
ArgumentOutOfRangeExceptionThe value of timeout is negative and is not equal to Timeout.Infinite milliseconds, or is greater than int.MaxValue milliseconds.

Remarks

The thread will not be scheduled for execution by the operating system for the amount of time specified. This method changes the state of the thread to include ThreadState.WaitSleepJoin.

You can specify Timeout.InfiniteTimeSpan for the timeout parameter to suspend the thread indefinitely. However, we recommend that you use other System.Threading classes such as System.Threading.Mutex, System.Threading.Monitor, System.Threading.EventWaitHandle, or System.Threading.Semaphore instead to sychronize threads or manage resources.

This overload of erload:System.Threading.Thread.Sleep uses the total number of whole milliseconds in timeout. Fractional milliseconds are discarded.

This method does not perform standard COM and SendMessage pumping.

Note:

If you need to sleep on a thread that has STAThreadAttribute, but you want to perform standard COM and SendMessage pumping, consider using one of the overloads of the erload:System.Threading.Thread.Join method that specifies a timeout interval.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0