SetWaitableTimer Function
The SetWaitableTimer function creates or opens a timer object and sets its available wait time to the system time. When the timer expires, the timer object is signaled.
This function is used to create periodic timers. For one-shot timers, use CreateTimerQueueTimer.
Syntax
BOOL SetWaitableTimer(
HANDLE hTimer,
const LARGE_INTEGER *lpDueTime,
LONG lPeriod,
PTIMER_CALLBACK pfnCompletionRoutine,
LPVOID pvArgToCompletionRoutine,
BOOL bResume
);
Parameters
| Parameter | Description |
|---|---|
hTimer |
A handle to the timer object. The CreateWaitableTimer function returns this handle.
|
lpDueTime |
A pointer to a LARGE_INTEGER structure that specifies the wait interval in hundred-nanosecond units.
|
lPeriod |
The period of the timer, in milliseconds.
|
pfnCompletionRoutine |
A pointer to an optional completion routine. If this parameter is NULL, the timer is a manual-reset timer. If it is not NULL, the timer is an auto-reset timer and pfnCompletionRoutine is the address of the function to be called when the timer expires.
|
pvArgToCompletionRoutine |
A pointer to a buffer that contains the argument to be passed to the pfnCompletionRoutine.
|
bResume |
If this parameter is TRUE, the timer is a system-wide timer that wakes the system from any hibernation or sleep state. The system's current time is used to calculate the due time.
If this parameter is FALSE, the timer is not a system-wide timer.
|
Return Value
| Value | Description |
|---|---|
TRUE |
The function succeeds. |
FALSE |
The function fails. To get extended error information, call GetLastError. |
Remarks
The SetWaitableTimer function is used to set a timer that can be waited on using functions such as WaitForSingleObject. If the timer expires, the timer object is signaled, and any threads waiting on it are released.
If pfnCompletionRoutine is not NULL, it is the address of a callback function that is executed when the timer expires. This callback function is responsible for signaling the timer object if necessary.
When bResume is TRUE, the timer becomes a system-wide timer. This means that if the system enters a hibernation or sleep state, the timer will wake the system when it expires.
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | winbase.h |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |