Edgar Huckert

Waitable timers in C++ under Windows

This program demonstrates the use of waitable timers in cooperation with callback routines. (additional source code is here and here). The program also demonstrates how to use critical sections under Windows. Waitable timers are in many cases a better replacement for the GUI timers (using WM_TIMER events). They are not restricted to GUI patterns and can thus be used also in console ("black windows") or server applications. I use waitable timers under Windows for my MIDI sequencers.

I have used a simple (queue based) protocol mechanism in the timer callback routine to demonstrate that the timer callback routine is called correctly. With this protocol that is dumped at the end of the main program I show also that the usual GetCurrenTime() routine is very unprecise (based on the16 ms interval inherited from DOS). By combinining GetCurrentTime() und a waitable timer you can build time inquiry routines that are much improved compared to GetCurrentTime() - but in the mean time better time inquiry routines (ex.: QueryPerformanceCounter()) are available in the Windows APIs.


If you want to contact me: this is my
mail address