system.timers.timer for very large intervals
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Peter Maco (VIP)
I created system.timers.timer for very long interval from TimeSpan.MaxValue:

myTimer = new System.Timers.Timer(TimeSpan.MaxValue.TotalMilliseconds)

After calling Enable = true I have a ArgumentOutOfRangeException exception.
I found out that timer internally uses System.Threading.Timer object and uses
constructor with "int" for dueTime. I suppose it explicitly converts double
to int without checking for overflow and System.Threading.Timer is created
with negative number for dueTime which throws an exception.
Is it a bug ?
Reply to this message...
 
    
Robert Jordan
Peter Maco wrote:

[Original message clipped]

No. The argument is obviously out of range, so what? ;-)

bye
Rob
Reply to this message...
 
    
Peter Maco (VIP)
Out of range ??? There is no range in documentation and no
ArgumentOutOfRangeException exception expected (in documentation). So I
consider it as bug.

"Robert Jordan" wrote:

[Original message clipped]

Reply to this message...
 
    
Robert Jordan
Peter Maco wrote:

[Original message clipped]

myTimer = new System.Timers.Timer(TimeSpan.MaxValue.TotalMilliseconds)

TimeSpan.MaxValue is equivalent to 9,223,372,036,854,775,807,
And this IS out of every range I can think about.

bye
Rob

[Original message clipped]

Reply to this message...
 
    
Girish bharadwaj
System.Timers.Timer takes a Double. I set it to Double.MaxValue with no
exceptions.
What version of .NET framework are you using?

--
Girish Bharadwaj
http://msmvps.com/gbvb
"Robert Jordan" <Click here to reveal e-mail address> wrote in message
news:ci4krk$d65$06$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Daniel Carlsson
Considering the documentation doesnt mention any
ArgumentOutOfRangeExceptions Id say its a bug yes.
If you really need to wait for a very long time before doing something you
should probably use a thread instead, which could contain an DateTime with
the time it should call a function.

"Peter Maco" <Peter Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I created system.timers.timer for very long interval from
TimeSpan.MaxValue:
[Original message clipped]

Reply to this message...
 
    
Willy Denoyette [MVP] (VIP)
"Peter Maco" <Peter Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

I would say this is a "documentation" bug.
The System.Timers.Timer takes a double as argument, but the value must be 0
=> interval <= Int32.MaxValue, or -1.
The same goes for System.Threading.Timer which takes an int or a long as
interval, but again the value of the interval is restricted to Int32.MaxVal.
This is because the underlying OS WaitableTimer object uses a long (signed
32 bit in C) for the period of the timer.

Willy.

Reply to this message...
 
 
System.ArgumentOutOfRangeException
System.DateTime
System.Double
System.Int32
System.Threading.Timer
System.Timers.Timer
System.TimeSpan




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com