Sleep (Windows CE 5.0)

Send Feedback

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



  • 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



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

Calling Sleep(INFINITE) is different on Windows CE-based platforms than it is for Windows-based desktop platforms. For Windows CE-based platforms, Sleep(INFINITE) is equivalent to calling SuspendThread(GetCurrentThread()). This means that the thread suspend count is incremented from 0 to 1 and can be resumed, or woken up, by another thread that calls ResumeThread on the sleeping thread. A Sleep(INFINITE) call on Windows-based desktop platforms is not a SuspendThread call, and calling ResumeThread on the sleeping thread does not resume the thread.

Be careful when using Sleep and code that directly or indirectly creates windows. An example of code that indirectly creates windows is COM CoInitialize.

If a thread creates 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.


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

See Also

CoInitialize | MsgWaitForMultipleObjects | MsgWaitForMultipleObjectsEx

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.