我想在Windows中创建一个简单的监视程序计时器,如果自上次计时器重置后经过一段时间,它将调用一个回调。
我想过使用timer queue timer,但似乎每次我想“推迟”计时器时都需要调用DeleteTimerQueueTimer
:
// This is called whenever data is received from a device.
// If not called within a certain period, timerCallbackFn will
// be invoked on a separate thread.
void resetWatchdog(void)
{
if (_timer->handle != NULL)
{
// cancel previous timer
DeleteTimerQueueTimer(NULL, (HANDLE)_timer->handle, NULL);
_timer->handle = NULL;
}
// create new "one shot" timer
CreateTimerQueueTimer(&_timer->handle,
NULL,
timerCallbackFn,
_timer,
_timer->intervalMs, // fire once, after the specified interval
0, // not periodic
0);
}
这是正确的做法吗?我每次都需要使用删除/创建吗?或者这是完全错误的工作计时器?