System.Timers.Timer Exception Number must be either non-negative or -1. Parameter name: dueTime
System.Timers.Timer Exception Number must be either non-negative or -1. Parameter name: dueTime
i got this exception while calling Timer.Start()
Number must be either non-negative or -1.
Parameter name: dueTime
can any one tell me the reason.
timer interval is set to 180000.
System.Timers.Timer Exception Number must be either non-negative or -1. Parameter name: dueTime
RICH525234
Check the value again, the exception means you've put a positive number in that is too large, and so gets turned into a negative number when converted to an int.
rSchild
i dont get any error when calling timer.Interval = Math.Pow(2, 31) + 1.
what timer are u using, is it system.timers.timer. for system.timers.timer interval is double and i dont think it can break with such small number. i m using .net 1.1
tamri
I have no idea why you wouldn't get an exception. However, it reproduces well with your original problem, somehow the Interval property gets set to an out-of-range value...
hwiz
Timer.Interval = 2^31 + 1
I get an ArgumentOutOfRange exception: "Number must be either non-negative and less than or equal to Int32.MaxValue or -1". That's pretty close to your exception. Your expression value is not close to triggering that, unless timeToWaitInWin = 3*60*1000...
Less likely: check if this only happens when the PC has been last booted 25 days ago (2^31 msec).
TheTheTheTheTheThe
just tried this, got no error
static void Main(string[] args){
Timer t =
new Timer();t.Elapsed +=
new ElapsedEventHandler(TimerElapsed);t.Interval = Math.Pow(2, 31) + 1;
t.Enabled =
true;Console.ReadLine();
}
public static void TimerElapsed(object sender, ElapsedEventArgs Args){
Console.WriteLine("Elapsed");
}
moemen.ahmed
KervyChoa
Martimus
i m using timer.Interval = timetoWaitinMin * 60 * 1000 for assigning to timer,
where timertoWaitInwin = 3.
this property in double so i dont think i can assign such a large number to it that it can turn into -ve, also it should give exception when assigning and not at timer.start().
i m using it in a service, which was running successfully for hours resuming after every 3 minutes and for once it stopped just because this call failed and timer didnt elapsed.
nglow
OK - that's the problem then. It's a shame it doesn't deal with that better.
Anjan Ghose
int num1 = (int)Math.Ceiling(this.Interval);