473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

about System.Threading.Timer interval

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

Nov 22 '05 #1
5 2320
violin wang <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
"violin wang" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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...ctortopic2.asp

-- Alan
Nov 22 '05 #3
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
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
Nov 22 '05 #4
Alan Pretre <no@spam> wrote:
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
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.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #5
-----Original Message-----
violin wang <an*******@discussions.microsoft.com> wrote:
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 goingfor 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 toclock changes, time resynchronization etc.
Thank you very much.--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: violin wang | last post by:
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...
3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
3
by: Andy | last post by:
Hello. I want to use System.Threading.Timer to control when my windows form is invalidated. I want it to update at 60 frames per second. But, if I set the Interval of my timer to anything less than...
1
by: Can Balioglu | last post by:
Hi, I don't know if it's already known but I found a bug in System.Timers.Timer class. The 'Interval' property accepts a double which specifies the interval between two 'Elapsed' events. The...
1
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
2
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
9
by: archana | last post by:
Hi all, I want to know about interval of timer. I am using timer in windows service.I head somewhere that when i set interval property of timer while setting interval, restart time of Pc is...
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.