System.Threading Timer Question

  • Thread starter Thread starter msnews
  • Start date Start date
M

msnews

Hi,

The best resolution I can get using System.Threading.Timer is 10ms which for
all pratical purposes is just fine. However, it is kind of anonying as the
Timer class does seem to indicate 1 millisec resolution and I have based my
ElapsedTime/Stopwatch classes on this assumption. The TimerCallback method
passed to the Timer is re-entrant. I do use High Performance counters for
more accurate timings and typically only use 1/10 of sec for my classes
using the Timer class. Newsgroups archives seem to converge on 100ms as
being typically reliable. Out of interest has anyone been able to collect a
tick count at millsec resolution.- that is actually seen a 1000 calls of
their TimerCallback per sec. Thanks, Matt.
 
I think you'd have to just have a thread in a loop, I doubt you will see a
1MS precision when using Threading.Timer

It'll still be tricky to achieve anything exactly every 1MS though I think.
 
The fact is, in Windows the thread scheduler limits the resolution of
time-based code, and if you're getting 10 ms resolution, you're doing
pretty well, given that the thread quantum is actually closer to 50 ms.
:)
I think the reason you can get <50ms is because multiple threads from teh
System ThreadPool are scheduled for future invocations of the TimerCallback-
this is why your TimerCallback method is supposed to be re-entrant. I have
conducted tests using both a phyical stopwatch and compared against the
Win32 HighPerformance Counters and the 10ms resolution is suprisingly quite
accurate. I'm only actually using 0.1 secs in my application, but my
curiousity got the better of me.

Thanks Pete and Peter for your replies and comments. Matt.
 
Back
Top