Search code examples
c#typestimerintdouble

assign a double value to timer interval


I am trying to assign a huge number of (milliseconds) to a timer interval, but i got this crash on "timer.Enabled = true" line !

The Exception Says :

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Number must be either non-negative and less than or equal to Int32.MaxValue or -1.

This is my code:

    CurrencyTimer.Interval = 2626086891.0;
    CurrencyTimer.Enabled = true;
    CurrencyTimer.AutoReset = true;
    CurrencyTimer.Elapsed += new System.Timers.ElapsedEventHandler(TimerWorker);
    CurrencyTimer.Start();

The Exception point to this line : CurrencyTimer.Enabled = true; Thanks,


Solution

  • The exception (and the documentation) is fairly clear about that the interval has to be between 0 and int.MaxValue. So, don't assign a value larger than that.

    For very long timer intervals you may have to split your interval in shorter intervals and count yourself. I'd also be curious why you think you need a 30-day timer interval ...