SetWaitableTimer

From aldeid
Jump to navigation Jump to search

Description

Activates the specified waitable timer. When the due time arrives, the timer is signaled and the thread that set the timer calls the optional completion routine.

Syntax

BOOL WINAPI SetWaitableTimer(
  _In_      HANDLE hTimer,
  _In_      const LARGE_INTEGER *pDueTime,
  _In_      LONG lPeriod,
  _In_opt_  PTIMERAPCROUTINE pfnCompletionRoutine,
  _In_opt_  LPVOID lpArgToCompletionRoutine,
  _In_      BOOL fResume
);

Parameters

hTimer [in]
A handle to the timer object. The CreateWaitableTimer or OpenWaitableTimer function returns this handle.
The handle must have the TIMER_MODIFY_STATE access right.
pDueTime [in]
The time after which the state of the timer is to be set to signaled, in 100 nanosecond intervals. Use the format described by the FILETIME structure. Positive values indicate absolute time. Be sure to use a UTC-based absolute time, as the system uses UTC-based time internally. Negative values indicate relative time. The actual timer accuracy depends on the capability of your hardware.
lPeriod [in]
The period of the timer, in milliseconds. If lPeriod is zero, the timer is signaled once.
If lPeriod is greater than zero, the timer is periodic. A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the CancelWaitableTimer function or reset using SetWaitableTimer.
If lPeriod is less than zero, the function fails.
pfnCompletionRoutine &#91.in, optional]
A pointer to an optional completion routine. The completion routine is application-defined function of type PTIMERAPCROUTINE to be executed when the timer is signaled.
lpArgToCompletionRoutine [in, optional]
A pointer to a structure that is passed to the completion routine.
fResume [in]
If this parameter is TRUE, restores a system in suspended power conservation mode when the timer state is set to signaled. Otherwise, the system is not restored. If the system does not support a restore, the call succeeds, but GetLastError returns ERROR_NOT_SUPPORTED.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Example

.text:004010F1                 call    ds:CreateWaitableTimerA
.text:004010F7                 push    0               ; fResume
.text:004010F9                 push    0               ; lpArgToCompletionRoutine
.text:004010FB                 push    0               ; pfnCompletionRoutine
.text:004010FD                 lea     edx, [esp+410h+FileTime]
.text:00401101                 mov     esi, eax
.text:00401103                 push    0               ; lPeriod
.text:00401105                 push    edx             ; lpDueTime
.text:00401106                 push    esi             ; hTimer
.text:00401107                 call    ds:SetWaitableTimer
.text:0040110D                 push    0FFFFFFFFh      ; dwMilliseconds
.text:0040110F                 push    esi             ; hHandle
.text:00401110                 call    ds:WaitForSingleObject
.text:00401116                 test    eax, eax