Hi,
I ran into a problem of assigning a double value to the Sytem.Timers.Interval.
The code is below
namespace TimerProblem
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
double temp = 19998441727;
Timer timer = new Timer();
timer.Elapsed += new ElapsedEventHandler(Foo);
timer.Enabled = true;
timer.Interval = temp;
}
private static void Foo(object source, ElapsedEventArgs e)
{
}
}
}
The error message is
Unhandled Exception: System.ArgumentOutOfRangeException: Number must be
either non-negative or -1.
Parameter name: dueTime
at System.Threading.Timer.Change(Int32 dueTime, Int32 period)
at System.Timers.Timer.UpdateTimer()
at System.Timers.Timer.set_Interval(Double value)
at TimerProblem.Class1.Main(String[] args) in
d:\awprojects\timerproblem\timerproblem\class1.cs:l
ine 27
I've even checked (with help from a colleaque) the system.dll and it seems
to take in a float64 which is equivalent to double.
Another value I've tried is
23759999999.0
Can anyone please help in determining the solution (an idea is
to manipulate the bits of the double)
Thanks
Phil Wilson - 27 Mar 2006 22:15 GMT
Internally (using Reflector) it seems to be using an int for the timer
value, the maximum value being 2147483647. System.Threading.Timer seems to
go to 4294967294.

Signature
Phil Wilson [MVP Windows Installer]
----
> Hi,
>
[quoted text clipped - 50 lines]
>
> Thanks
Christopher Reed - 28 Mar 2006 03:42 GMT
Because your value was greater than 2^31 - 1, the system is trying to
convert an integer to a double. In this case, it's folding over itself and
is most likely being represented as a negative number. Try adding a "D" to
end of the number and see what happens.

Signature
Christopher A. Reed
"The oxen are slow, but the earth is patient."
> Hi,
>
[quoted text clipped - 50 lines]
>
> Thanks