We help IT Professionals succeed at work.

Need a more accurate timer than TTimer.

HorridMan
HorridMan asked
on
If you set TTimer's interval to 100ms and furnish a very simple OnTimer event handler it runs at about 0.91 times the speed of a real clock, even at so-called "Realtime" and "Time_Critical" priority. I need something accurate. I thought I might be able to use the CPU clock. Can anyone tell me if that's possible? Or is any other way better?

Thankyou.
Comment
Watch Question

Software Developer
CERTIFIED EXPERT
Commented:
you can find some timers with more accuracy in torry site

http://www.torry.net/timers.htm

Commented:
Hi HorridMan!

Look at the Alex Simmonetti Delphi page http://www.bhnet.com.br/~simonet/howtoprojs.htm, here is a very nice example on how to create highly accurate multimedia times (with resolution of milliseconds).

Best regards, Ivo.

Commented:
Another solution is to spawn another thread as I did a time ago in my component. In execute method I used a call to api WaitForSingleObject where I supplied a handle to an api Event object as well as interval for which I need to wait, then in case the result of this call was by TimeOut I triggered the OnTimer event either directly or indirectly by calling synchronize in case one would access the components in OnTimer handler. Then I reset the event and continue in loop. Using this way of waiting caused cpu load to be very small for a spawned task.

Best regards, Ivo.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.