473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about System.Threadin g.Timer interval

hi
When I set up a timer in my program, I used public
Timer(TimerCall back, 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 2363
violin wang <an*******@disc ussions.microso ft.com> wrote:
When I set up a timer in my program, I used public
Timer(TimerCall back, 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 resynchronizati on etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
"violin wang" <an*******@disc ussions.microso ft.com> wrote in message
news:03******** *************** *****@phx.gbl.. .
When I set up a timer in my program, I used public
Timer(TimerCall back, 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.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
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 resynchronizati on 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.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
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 resynchronizati on 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.co m>
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*******@disc ussions.microso ft.com> wrote:
When I set up a timer in my program, I used public
Timer(TimerCall back, 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 resynchronizati on etc.
Thank you very much.--
Jon Skeet - <sk***@pobox.co m>
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
301
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 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...
3
16878
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 interval property inside the event handler? Example follows: Constructor: mTimer = new System.Timers.Timer(20000); mTimer.AutoReset = false;
3
5601
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 dueTime) is always set to 6 days, 23 hours, 59 minutes, .. Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely). I have made a lot of tests and this issue does not occur with a delay < 1 day .. Any suggestion
3
3312
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 30ms, the event isn't triggered. That means I am stuck in the neighborhood of 30 frames per second. The reason why I am doing this at all is because when I tried to Invalidate my form from with in the OnPaint call, other windows suddenly...
1
7709
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 'Start' method just sets the 'Enabled' property to true. And the problem lies in the 'Enabled' property. It casts the interval value to an integer and calls the constructor of the System.Threading.Timer class which only accepts a non-negative...
1
3292
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 objects which all fire into my OnTimer( object state ) function very nicely. I pass in an object "o" on creation of this timer which I subsequently get passed to me in my OnTimer function. Now in the OnTimer function I want to modify the object...
2
13197
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 System.Timers.Timer but i had to remove it because of known bug(842739). Now i am using System.Threading.Timer. It executes routine fine but the delay time is sporadic, sometimes it executes routine after 5 minutes, sometimes 10 minuete, 13...
2
9000
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
2643
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 consider. My question is if i am using timer in my windows service, is there any place where interval related information like interval set used by my
4
14394
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 functionality of the sub working fine but I cannot figure out how to run the timer. The sub DoSomethingHere() needs to run every 60 seconds. It doesn't need to change the interval or anything like that. It just needs to run every 60 seconds as long as...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.