tags:

views:

46

answers:

1

Is there a Monotonic WaitableTimer available in C#, or even in Win32 that I could wrap?

Currently I'm using the Win32 CreateWaitableTimer, but if the system clock gets modified it will skew the timer values and cause things to happen before or after they are scheduled to occur.

The only Monotonic clock source I've found available in Windows XP is GetTickCount(), but I was hoping to not have to write my own timer using this.

+1  A: 

SetWaitableTimer() supports two ways to set the due time. A positive value sets absolute time, it will be affected by the clock. A negative value sets relative time, it will not be affected by the clock. You want the latter.

Any .NET timer will not be affected by the clock. Not even the time zone or DateTime.Now changes. Check out CultureInfo.ClearCachedData(). Using System.Threading.Timer ought to be a good managed replacement.

Hans Passant
Thanks! I didn't realize I could use a negative value. The .Net timers seem to fail under a heavy load, so I'm going avoid using them.
Steven Behnke