Note that there are some explanatory texts on larger screens.

plurals
  1. POAccurate Windows timer? System.Timers.Timer() is limited to 15 msec
    primarykey
    data
    text
    <p>I need an accurate timer to interface a Windows application to a piece of lab equipment.</p> <p>I used System.Timers.Timer() to create a timer that ticks every 10 msec, but this clock runs slow. For example 1000 ticks with an interval of 10 msec should take 10 wall-clock seconds, but it actually takes more like 20 wall-clock sec (on my PC). I am guessing this is because System.Timers.Timer() is an interval timer that is reset every time it elapses. Since it will always take some time between when the timer elapses and when it is reset (to another 10msec) the clock will run slow. This probably fine if the interval is large (seconds or minutes) but unacceptable for very short intervals.</p> <p>Is there a function on Windows that will trigger a procedure every time the system clock crosses a 10 msec (or whatever) boundary?</p> <p>This is a simple console application.</p> <p>Thanks</p> <p>Norm</p> <p>UPDATE: System.Timers.Timer() is extremely inaccurate for small intervals.</p> <p>I wrote a simple program that counted 10 seconds several ways:</p> <p>Interval=1, Count=10000, Run time = 160 sec, msec per interval=16</p> <p>Interval=10, Count=1000, Run time = 16 sec, msec per interval=15</p> <p>Interval=100, Count=100, Run time = 11 sec, msec per interval=110</p> <p>Interval=1000, Count=10, Run time = 10 sec, msec per interval=1000</p> <p>It seems like System.Timers.Timer() cannot tick faster that about 15 msec, regardless of the interval setting.</p> <p>Note that none of these tests seemed to use any measurable CPU time, so the limit is not the CPU, just a .net limitation (bug?)</p> <p>For now I think I can live with an inaccurate timer that triggers a routine every 15 msec or so and the routine gets an accurate system time. Kinda strange, but...</p> <p>I also found a shareware product ZylTimer.NET that claims to be a much more accurate .net timer (resolution of 1-2 msec). This may be what I need. If there is one product there are likely others.</p> <p>Thanks again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload