Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / March 2006

Tip: Looking for answers? Try searching our database.

Visual Studio 2003 v.1.1.4322 C# System.Timers.Interval problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DaemonOnMe - 27 Mar 2006 17:41 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.