1

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,

Community
  • 1
  • 1
Qutaiba
  • 145
  • 1
  • 13

2 Answers2

5

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 ...

Joey
  • 344,408
  • 85
  • 689
  • 683
0

Use:

Threading.Timer

The constructor has several overloads two of which accept TimeSpan or Int64 values. The documentation does not mention limits on the values except for the intrinsic limitations of the data types.

Kevin
  • 1,462
  • 9
  • 9