I created a win32 timer. And assign a timerproc call back to it. My timer calls timerproc every 500 ms, but I wonder how this happens ? Does it wait timerproc to finihs its job ? or call the timer proc eventhough previous thread is working ? I tested the code, acording to my test. Timer waits its callback to return. However I saw a waitable timer consept and that made me ask this question.
Asked
Active
Viewed 146 times
0
-
SetTimer() depends on the message loop in your program. The one that delivers all operating system notifications, the timer is just one of them. – Hans Passant Jan 20 '15 at 11:31
-
Also see [WM_TIMER documentation at MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644902%28v=vs.85%29.aspx): _"The message is posted by the GetMessage or PeekMessage function... DispatchMessage will call the TimerProc callback function specified in the call to the SetTimer function used to install the timer."_ – dewaffled Jan 20 '15 at 11:42
-
just to clerify the subject: Settimer sends a windows message, for example WM_TIMER. If I process messages with GetMessage, my TIMERPROC can not be called until it finishes. However if I use PeekMessage, TIMERPROC will be called every 500 ms. Right ? – Cihan Jan 20 '15 at 11:46
-
1SetTimer does not generate message. It is generated periodically by GetMessage or PeekMessage after SetTimer called. Then the message is processed by DispatchMessage that calls timer callback. If timer handler blocks message loop, obviously no other messages would be processed including WM_TIMER. By itself Windows timers do not involve any multithreading - all windows messages are processed in a single thread one by one with message loop. – dewaffled Jan 20 '15 at 12:26