Reputation: 23
I can't delete my Timer Queue properly. I always get the following error: Unhandled exception at 0x77a915de in Timer.exe: 0xC0000005: Access violation reading location 0x00000020.
I have a simple timer callback function:
void CALLBACK TimerProc(void* lpParameter, BOOLEAN TimerOrWaitFired)
{
cout << "The timer is working!" << endl;
}
And here is my main function where I create and delete the timer:
int main(int argc, char *argv[])
{
HANDLE hTimer;
// Create timer
CreateTimerQueueTimer(
&hTimer, // Timer handler
NULL, // Default timerqueue
(WAITORTIMERCALLBACK)TimerProc, // Callback function
0,
0,
(DWORD)2000, // Period value = 2 seconds
WT_EXECUTEINTIMERTHREAD );
// Do other tasks
// e.g. Sleep(10000);
// Delete Timer
if ( !DeleteTimerQueueEx(hTimer, NULL) )
{
cout << GetLastError() << endl;
}
return 0;
}
The debugger always stops at the DeleteTimerQueueEx line. Why does this failure occurs?
Upvotes: 1
Views: 2437
Reputation: 175936
You are not creating your own queue (CreateTimerQueue
) rather you are adding to the default timer queue which is not deletable, instead delete the timer itself (DeleteTimerQueueTimer
).
If you want to group multiple timers, create your own queue which you can then subsequently delete.
Upvotes: 4