2011-02-10, 12:31 AM
I need to run a particular bit of code in a System Service every hour shortly after the hour (~5 mins but not too critical).
I'm doing this with a System.Timers.Timer and setting it to fire every 3600000 ms which is working but I've noticed in 12 hours, it has drifted forwards by over 1 minute (in particular between the ~4pm -> ~5pm calls)...
I could check the 'Minute' part of DateTime.Now each time it's called and recalculate the next delay but I was just wondering if there's anything more accurate for doing this.
I'm sure I've done something similar in the past but can't think of how I did it and Google seems to just throw up examples of System.Timers.Timer.
I'm doing this with a System.Timers.Timer and setting it to fire every 3600000 ms which is working but I've noticed in 12 hours, it has drifted forwards by over 1 minute (in particular between the ~4pm -> ~5pm calls)...
Code:
09/02/2011 11:05:46.385 onTimerElapsed called...
09/02/2011 12:05:45.855 onTimerElapsed called...
...
09/02/2011 16:05:43.735 onTimerElapsed called...
09/02/2011 17:04:30.159 onTimerElapsed called...
...
09/02/2011 23:04:25.535 onTimerElapsed called...
I'm sure I've done something similar in the past but can't think of how I did it and Google seems to just throw up examples of System.Timers.Timer.