When you would like to carry out a certain task regularly over time, you would use some kind of timing event so that the task could be taken place whenever an event arises. For Win32 applications,

UINT_PTR SetTimer(      
    HWND hWnd,
    UINT_PTR nIDEvent,
    UINT uElapse,
    TIMERPROC lpTimerFunc
);

and the associated event handler

Sub OnTimer
(
    bstrURLItem As String,
    lFlags As LONG
)


would be a perfect option to use.

However, the accuracy of the timer can be very poor for some situations. An accuracy test performed by Chih-Hao Tsai at the University of Illinois at Urbana-Champaign indicates that the accuracy of SetTimer showed average error of 10 ms [1].

I found this out since I had to sample some data from hardware within 10 ms at work. The max resolution that I was able to acheive with SetTimer() was about 15 ms. The reason for the (relatively) inaccurate timing could be found from Windows NT SRMS Service research page by Azer Bestavros and Adrian Prezioso at [2]. Apparently, the 15ms resolution wasn't good enough. So I was looking for a better solution.

After doing some research (but more like web surfing), I found out that the Multimedia Timers provided in Winmm.lib guarantees better timing resolution. Reported to provide resolution up to 1 ms. [3] is an excellent reference written by Nemanja Trifunovic for Multimedia Timers and some other various timers as it discusses their characteristics and uses.

In [3] there are some tiny details that I suppose were omitted accidentally by the author. But I also forgot what it was. I will try to include that information later asap.


REFERENCES

[1] http://web.archive.org/web/20010621175106/home.educities.edu.tw/hao/hao510/w98timer/

[2] http://www.cs.bu.edu/groups/realtime/SRMS-NT/index.htm
[3] http://www.codeproject.com/KB/system/timers_intro.aspx
Posted by Dansoonie