TimerAPCProc() Not Being Called With SetWaitableTimer()
-
I wrote the below code in an attempt to set a 500ms timer. CreateWaitableTimer returns a valid handle and SetWaitableTimer() returns 1 indicating success, however TimerAPCProc() never gets called. Can anybody see what's wrong with this code?
VOID CALLBACK __stdcall TimerAPCProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { } void SetTimer() { m_hTimer = CreateWaitableTimer(NULL, false, NULL); LARGE_INTEGER liInterval; liInterval.QuadPart = -500000000; int dSuccess = SetWaitableTimer(m_hTimer, &liInterval, 0, TimerAPCProc, NULL, false); }
Thanks for any help you can offer. -
I wrote the below code in an attempt to set a 500ms timer. CreateWaitableTimer returns a valid handle and SetWaitableTimer() returns 1 indicating success, however TimerAPCProc() never gets called. Can anybody see what's wrong with this code?
VOID CALLBACK __stdcall TimerAPCProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { } void SetTimer() { m_hTimer = CreateWaitableTimer(NULL, false, NULL); LARGE_INTEGER liInterval; liInterval.QuadPart = -500000000; int dSuccess = SetWaitableTimer(m_hTimer, &liInterval, 0, TimerAPCProc, NULL, false); }
Thanks for any help you can offer.Is the thread that creates the timer exiting too fast? Also read http://msdn.microsoft.com/en-us/library/ms681951(VS.85).aspx[^] to know when APC callbacks are called.
-
Is the thread that creates the timer exiting too fast? Also read http://msdn.microsoft.com/en-us/library/ms681951(VS.85).aspx[^] to know when APC callbacks are called.
Thanks for the reply and information. The timer is being created in the main thread so it's definitely not a problem of it exiting too soon. I also tried setting the time to -1 just to try and get it to call the TimerAPCProc but still it wouldn't. I solved the problem by switching to SetTimer(). For some reason I thought SetTimer() worked in seconds rather than milliseconds and that's the only reason I was using SetWaitableTimer(). I was looking for an alternative time and noticed SetTimer() took a value in milliseconds so it was fine for what I needed. I still don't understand why SetWaitableTimer() wouldn't work but it doesn't really matter now.