about System.Threading.Timer interval

  • Thread starter Thread starter violin wang
  • Start date Start date
V

violin wang

hi
When I set up a timer in my program, I used public
Timer(TimerCallback, object, TimeSpan, TimeSpan)
constructor. I want the timer to fire after a mount of
time, so I wrote "new Timer(new TimeCallback
(some_function), null, timeDiff, new TimeSpan)".When I
ran the program, VS.NET popped a MsgBox that told me the
timer interval must be less than 2^32-2.Actually, the
argument "timeDiff" could be very large(maybe 2 or 3
years).How can I dealing with this problem?

thanks
violin
 
violin wang said:
When I set up a timer in my program, I used public
Timer(TimerCallback, object, TimeSpan, TimeSpan)
constructor. I want the timer to fire after a mount of
time, so I wrote "new Timer(new TimeCallback
(some_function), null, timeDiff, new TimeSpan)".When I
ran the program, VS.NET popped a MsgBox that told me the
timer interval must be less than 2^32-2.Actually, the
argument "timeDiff" could be very large(maybe 2 or 3
years).How can I dealing with this problem?

I'd suggest having a timer which actually fired once a day, only going
for the "accurate" real firing time when it was less than a day away.
That way there'd be less chance of missing the correct time due to
clock changes, time resynchronization etc.
 
violin wang said:
When I set up a timer in my program, I used public
Timer(TimerCallback, object, TimeSpan, TimeSpan)
constructor. I want the timer to fire after a mount of
time, so I wrote "new Timer(new TimeCallback
(some_function), null, timeDiff, new TimeSpan)".When I
ran the program, VS.NET popped a MsgBox that told me the
timer interval must be less than 2^32-2.Actually, the
argument "timeDiff" could be very large(maybe 2 or 3
years).How can I dealing with this problem?

There's a different Timer() constructor that takes 64-bit values. You can
use that instead of TimeSpan.

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemthreadingtimerclassctortopic2.asp

-- Alan
 
Jon Skeet said:
I'd suggest having a timer which actually fired once a day, only going
for the "accurate" real firing time when it was less than a day away.
That way there'd be less chance of missing the correct time due to
clock changes, time resynchronization etc.

It's doubtful the computer will even be up and running that long anyway
without needing to be rebooted... Every Windows Update makes you reboot.

-- Alan
 
Alan Pretre said:
It's doubtful the computer will even be up and running that long anyway
without needing to be rebooted... Every Windows Update makes you reboot.

That was my feeling as well, but maybe the OP has some special set of
circumstances :)
 
-----Original Message-----


I'd suggest having a timer which actually fired once a day, only going
for the "accurate" real firing time when it was less than a day away.
That way there'd be less chance of missing the correct time due to
clock changes, time resynchronization etc.
Thank you very much.
--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
 
Back
Top