Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In System.Timers.Timer class
'Interval' property accepts a double which specifies the interval
between two 'Elapsed' events.
But if we set a value greater that an int to the Interval(>bigger that 2,147,483,647)

and call Start() it throws a exception..!!!


Actually, the type of System.Timers.Timer.Interval is a double. I wonder why its double?, although it cannot be greater than Int32.MaxValue...!!!


Please Share your thoughts...!!!
Posted
Updated 12-Jul-12 1:35am
v5
Comments
Sergey Alexandrovich Kryukov 8-Feb-12 0:34am    
What does it mean: "a value greater than an 'int'"?
--SA
CGN007 8-Feb-12 0:37am    
Greater than int.Max Value:2,147,483,647.
Sergey Alexandrovich Kryukov 8-Feb-12 0:35am    
What is "System.Timer"? A type? I don't know it.
--SA
CGN007 8-Feb-12 0:41am    
In System.Timers.Timer class..
Sorry,Please Check the updated question...!!!
Sergey Alexandrovich Kryukov 8-Feb-12 0:45am    
Better. Now, I wonder why?!

I hope aniketyadav explained that for you... :-)

By the way, asking about exception, always provide exception information.
--SA

The answer is: this exception is explicitly documented in the MSDN help page on this property: http://msdn.microsoft.com/en-us/library/system.timers.timer.interval.aspx[^].

Section "Exceptions" explicitly states:
The interval is greater than Int32.MaxValue, and the timer is currently enabled. (If the timer is not currently enabled, no exception is thrown until it becomes enabled)


You really need to follow these important instructions:

Microsoft Q209354.

—SA
 
Share this answer
 
v2
Comments
CGN007 8-Feb-12 1:07am    
Actually, the type of System.Timers.Timer.Interval is a double.
I wonder why its double?, although it cannot be greater than Int32.MaxValue...!!!
The INT Range In C# Is -2,147,483,648 to 2,147,483,647, Which Is A Signed 32-Bit Integer.
Why Do You Want To Set The Timer Interval Greater Than This Range?
As 1 Sec = 1000 Milliseconds

And Even If You Set The Interval To: 2147483647 Then
2,147,483,647 milliseconds is equivalent to 35800 minutes

Do you want your timer to run for such a long time?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Feb-12 0:52am    
Good point, of course, but not an answer.

Please see my answer (last link is especially interesting :-)
--SA
[no name] 12-Jul-12 8:06am    
In other words: 28 days later...
CGN007 8-Feb-12 1:32am    
yes of-course...
Actually, the type of System.Timers.Timer.Interval is a double. I wonder why its double?, although it cannot be greater than Int32.MaxValue...!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900