C
Can Balioglu
Hi,
I don't know if it's already known but I found a bug in System.Timers.Timer
class.
The 'Interval' property accepts a double which specifies the interval
between two 'Elapsed' events. The 'Start' method just sets the 'Enabled'
property to true. And the problem lies in the 'Enabled' property. It casts
the interval value to an integer and calls the constructor of the
System.Threading.Timer class which only accepts a non-negative integer
or -1. (I used Lutz Roeder's .Net Reflector to find this out) But casting
the interval (which is a double) to an integer might cause a range overflow.
I have a timer class which needs to be fired every 31 days. But it throws an
exception because 31 days makes approx. 2642922562 milliseconds
Casting this value to an Int32 makes it -2147483648 and this causes an
ArgumentOutOfRange exception in the constructor.
I don't know if it's already known but I found a bug in System.Timers.Timer
class.
The 'Interval' property accepts a double which specifies the interval
between two 'Elapsed' events. The 'Start' method just sets the 'Enabled'
property to true. And the problem lies in the 'Enabled' property. It casts
the interval value to an integer and calls the constructor of the
System.Threading.Timer class which only accepts a non-negative integer
or -1. (I used Lutz Roeder's .Net Reflector to find this out) But casting
the interval (which is a double) to an integer might cause a range overflow.
I have a timer class which needs to be fired every 31 days. But it throws an
exception because 31 days makes approx. 2642922562 milliseconds
Casting this value to an Int32 makes it -2147483648 and this causes an
ArgumentOutOfRange exception in the constructor.