Time Elapsed Timer

Posted on  by admin
Some information relates to prerelease product that may be substantially modified before it’s released.

Microsoft makes no warranties, express or implied, with respect to the information provided here.

The following example instantiates a Timer object that fires its Timer.Elapsed event every two seconds (2000 milliseconds), sets up an event handler for the event, and starts the timer.

nbrooks
17.8k
2

The Elapsed event is raised if the Enabled property is true and the time interval (in milliseconds) defined by the Interval property elapses.

If the AutoReset property is true, the event is raised repeatedly at an interval defined by the Interval property; otherwise, the event is raised only once, the first time the Interval value elapses.

Adam Lear♦Adam Lear
36.7k5

If the SynchronizingObject property is null,the Elapsed event is raised on a ThreadPool thread.

If the processing of the Elapsed event lasts longer than Interval, the event might be raised again on another ThreadPool thread.

AdamAdam
3,5031

The example code for the Stop method shows one way to avoid this race condition. Even if SynchronizingObject is not null, Elapsed events can occur after the Dispose or Stop method has been called or after the Enabled property has been set to false, because the signal to raise the Elapsed event is always queued for execution on a thread pool thread.

One way to resolve this race condition is to set a flag that tells the event handler for the Elapsed event to ignore subsequent events.

The Timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event.

This behavior is subject to change in future releases of .NET Framework. Sapling’s Elapsed Timer is a device that allows a user to shift the display on a digital clock from the time to a count up or countdown display.

Connected to a Sapling digital clock (3200 or 3300 series only), this device can be utilized in a variety of settings where keeping track of the elapsed time is needed.

Sapling’s Elapsed Timer is a Sapling 3200 or 3300 digital clock interfacing with an Elapsed Timer Control Panel, which enables a user to immediately change the display on the digital clock from showing time to showing a count up or a countdown.

Not the answer you're looking for? Browse other questions tagged c#timer or ask your own question.