System.Threading.Thread.Sleep Method

Suspends the current thread for the specified number of milliseconds.

Syntax

public static void Sleep (int millisecondsTimeout)

Parameters

millisecondsTimeout
The number of milliseconds for which the thread is suspended. A value of zero (0) has no effect.

Exceptions

TypeReason
ArgumentOutOfRangeExceptionThe value of millisecondsTimeout is negative and is not equal to Timeout.Infinite .

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.Infinite for the millisecondsTimeout 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 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