473,408 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Bug in System.Timers.Timer class

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.
Nov 16 '05 #1
1 7680
IMO it's not a bug but merely a design flaw and a "documentation bug":
- "Interval" should have been an Int32 but not a double.
- the documentation should clearly state that Int32.Max is the max. value
for Interval , like it's done for System.Threading.Timer (but isn't it
confusing to say the max value of a double arg. is Int32.Max?).
The motivation for this is simple:
System.Timers.Timer and System.Threading.Timer are simple wrappers around
Win32 Waitable timer objects.
The period argument of the SetWaitableTimer API is a signed int (32 bit),
the value of this must be =>0, any other value makes the function fail.
That means that Int32.Max is the largest value for the Interval(24.8 days).

To solve your problem however, you could fire once a day and increment a
counter until it reaches 32.

Willy.

"Can Balioglu" <balioglu@DONOTSPAM_in.tum.de> wrote in message
news:uM**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
1
by: logdenav | last post by:
Hello I'm testing the performance of the System.Timers.Timer class. I created a small program that create 100 User objects. Each USer object create a MyTimer object. The constructor of the User...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
2
by: BobAtVandy | last post by:
I'll greatly appreciate any help on this. Actually 2 questions: 1. I believe I need to use the Windows timer System.Timers.Timer . The examples I find on the web all access that timer by...
5
by: Brian | last post by:
Hello all. I have a simple application that I was using to test and understand the System.Timers.Timer and noticed that when I stop the application, on occasion, it throughs the following...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.