Sleep function
Namespace: Windows
| Header: Windows.h
Syntax
VOID WINAPI Sleep(
DWORD dwMilliseconds
);
Parameters
dwMilliseconds | The amount of time, in milliseconds, that the current thread is to be suspended. A value of zero yields the thread’s remaining quantum. |
---|
Return value
This function does not return a value.
Remarks
- Sleep suspends the execution of the current thread for at least the specified interval.
- The actual sleep time may be greater than the requested interval due to system scheduling.
- For higher precision timing, consider using CreateWaitableTimer or timeBeginPeriod.
- A value of
INFINITE
(0xFFFFFFFF) can be passed to put the thread into an indefinite wait state (use with caution).
Note: On Windows 8 and later, the system may round the interval up to the nearest multiple of the system timer resolution.
Example
#include <windows.h>
#include <stdio.h>
int main(void)
{
printf("Waiting for 2 seconds...\\n");
Sleep(2000); // 2000 milliseconds = 2 seconds
printf("Done!\\n");
return 0;
}