How to get accurate time (to 100 nano second) in C#?

  • Thread starter Thread starter Andy Lee
  • Start date Start date
Change computer language. If your app depends so much on highly-accurate
timing, then the garbage collector alone (and the fact that you have little
control over it) will mess up your timings.
 
I think Win32s' QueryPerformanceCounter is the only thing that can do better
then milliseconds.
 
Ticks is a good time measure. There are 10 000 ticks per millisecond. See TimeSpan.TicksPerMillisecond constant.
 
Andy,
In addition to HKM's suggestion:

Here are C# & VB.NET versions of HKM's post:
http://support.microsoft.com/default.aspx?scid=kb;en-us;306979
http://support.microsoft.com/default.aspx?scid=kb;en-us;306978

The February 2004 issue of MSDN Magazine had a good article on Timers in
..NET:

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx

The March 2004 issue of MSDN Magazine has a second good article on Timers in
..NET:

http://msdn.microsoft.com/msdnmag/issues/04/03/default.aspx

Hope this helps
Jay
 
Back
Top