System.Diagnostics.Stopwatch reliablity

  • Thread starter Thread starter kerplunkwhoops
  • Start date Start date
K

kerplunkwhoops

Hello

I am wanting to use the high accuracy of System.Diagnostics.Stopwatch
to get the current time using GetTimeSpan.

Underneath, System.Diagnostics.Stopwatch.GetTimeStamp uses the win32
API QueryPerformanceCounter which has a reliability issue and can jump
forward unexpectedly (http://support.microsoft.com/kb/274323). Does
System.Diagnostics.Stopwatch.GetTimeStamp take this issue into
consideration and perform a check with GetTickCount?

I am considering using win32 TimeGetTime which is accurate to 1ms
(http://gpwiki.org/index.php/VB:Timers), but would prefer to use the
managed System.Diagnostics.Stopwatch if possible.

Many thanks

Paul
 
Paul,

The documentation doesn't state that it performs this check, so I
wouldn't count on it. Looking at the code for the Stopwatch class in
Reflector, I can see that it doesn't perform the check either, but that is
an implementation detail.

If you want this behavior, you will have to implement it yourself.
 
Back
Top