CreateThreadpoolTimer function (Windows)

Switch View :
ScriptFree
CreateThreadpoolTimer function

Applies to: desktop apps only

Creates a new timer object.

Syntax

PTP_TIMER WINAPI CreateThreadpoolTimer(
  __in         PTP_TIMER_CALLBACK pfnti,
  __inout_opt  PVOID pv,
  __in_opt     PTP_CALLBACK_ENVIRON pcbe
);

Parameters

pfnti [in]

The callback function to call each time the timer object expires. For details, see TimerCallback.

pv [in, out, optional]

Optional application-defined data to pass to the callback function.

pcbe [in, optional]

A TP_CALLBACK_ENVIRON structure that defines the environment in which to execute the callback. The InitializeThreadpoolEnvironment function returns this structure.

If this parameter is NULL, the callback executes in the default callback environment. For more information, see InitializeThreadpoolEnvironment.

Return value

If the function succeeds, it returns a TP_TIMER structure that defines the timer object. Applications do not modify the members of this structure.

If the function fails, it returns NULL. To retrieve extended error information, call GetLastError.

Remarks

To set the timer object, call the SetThreadpoolTimer function.

To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or higher.

Examples

For an example, see Using the Thread Pool Functions.

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

CloseThreadpoolTimer
IsThreadpoolTimerSet
SetThreadpoolTimer
Thread Pools
WaitForThreadpoolTimerCallbacks

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Community Content

JensG
TimerCallback may be called re-entrant
It is not obvious, that the TimerCallback function can be called quasi re-entrant even on simple scenarios.

This happens, when
a) the execution of the callback code takes longer than the timer interval time is set
b) a free thread is available in the pool.

As a consequence, additional synchronisation efforts may become necessary in the TimerCallback code.
JensG