Share via


Sleep

This function suspends the execution of the current thread for a specified interval.

void Sleep(
  DWORD dwMilliseconds
); 

Parameters

  • dwMilliseconds
    [in] Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If no other threads of equal priority are ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE causes an infinite delay.

Return Values

None.

Remarks

A thread can relinquish the remainder of its time slice by calling this function with a sleep time of zero milliseconds.

Be careful when using Sleep and code that directly or indirectly creates windows. One example of code that indirectly creates windows is COM CoInitialize. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. A thread that uses Sleep with an infinite delay can cause the system to deadlock. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than Sleep.

Requirements

OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.

See Also

CoInitialize | MsgWaitForMultipleObjects | MsgWaitForMultipleObjectsEx

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.