次の方法で共有


Sleep (Compact 2013)

3/28/2014

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

Syntax

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 Value

None.

Remarks

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 Embedded Compact-based platforms than it is for Windows-based desktop platforms. For Windows Embedded Compact-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.

Requirements

Header

winbase.h

Library

Nkstub.lib

See Also

Reference

Process and Thread Functions

Other Resources

CoInitialize
MsgWaitForMultipleObjects
MsgWaitForMultipleObjectsEx