CreateWaitableTimerW function (synchapi.h)
Creates or opens a waitable timer object.
To specify an access mask for the object, use the CreateWaitableTimerEx function.
Syntax
HANDLE CreateWaitableTimerW(
[in, optional] LPSECURITY_ATTRIBUTES lpTimerAttributes,
[in] BOOL bManualReset,
[in, optional] LPCWSTR lpTimerName
);
Parameters
[in, optional] lpTimerAttributes
A pointer to a SECURITY_ATTRIBUTES structure that specifies a security descriptor for the new timer object and determines whether child processes can inherit the returned handle.
If lpTimerAttributes is NULL, the timer object gets a default security descriptor and the handle cannot be inherited. The ACLs in the default security descriptor for a timer come from the primary or impersonation token of the creator.
[in] bManualReset
If this parameter is TRUE, the timer is a manual-reset notification timer. Otherwise, the timer is a synchronization timer.
[in, optional] lpTimerName
The name of the timer object. The name is limited to MAX_PATH characters. Name comparison is case sensitive.
If lpTimerName is NULL, the timer object is created without a name.
If lpTimerName matches the name of an existing event, semaphore, mutex, job, or file-mapping object, the function fails and GetLastError returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.
The name can have a "Global" or "Local" prefix to explicitly create the object in the global or session namespace. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces. Fast user switching is implemented using Terminal Services sessions. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
The object can be created in a private namespace. For more information, see Object Namespaces.
Return value
If the function succeeds, the return value is a handle to the timer object. If the named timer object exists before the function call, the function returns a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Remarks
The handle returned by CreateWaitableTimer is created with the TIMER_ALL_ACCESS access right; it can be used in any function that requires a handle to a timer object, provided that the caller has been granted access. If a timer is created from a service or thread that is impersonating a different user, you can either apply a security descriptor to the timer when you create it, or change the default security descriptor for the creating process by changing its default DACL. For more information, see Synchronization Object Security and Access Rights.
Any thread of the calling process can specify the timer object handle in a call to one of the wait functions.
Multiple processes can have handles to the same timer object, enabling use of the object for interprocess synchronization.
- A process created by the CreateProcess function can inherit a handle to a timer object if the lpTimerAttributes parameter of CreateWaitableTimer enables inheritance.
- A process can specify the timer object handle in a call to the DuplicateHandle function. The resulting handle can be used by another process.
- A process can specify the name of a timer object in a call to the OpenWaitableTimer or CreateWaitableTimer function.
To compile an application that uses this function, define _WIN32_WINNT as 0x0400 or later. For more information, see Using the Windows Headers.
To associate a timer with a window, use the SetTimer function.
Examples
For an example that uses CreateWaitableTimer, see Using Waitable Timer Objects.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2003 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | synchapi.h (include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |