Elapsed Event
Collapse the table of content
Expand the table of content

Timer.Elapsed Event

Occurs when the interval elapses.

Namespace:  System.Timers
Assembly:  System (in System.dll)

[<TimersDescriptionAttribute("TimerIntervalElapsed")>]
member Elapsed : IEvent<ElapsedEventHandler,
    ElapsedEventArgs>

If Enabled is set to true and AutoReset is set to false, the Timer raises the Elapsed event only once, the first time the interval elapses.

If Interval is set after the Timer has started, the count is reset. For example, if you set the interval to 5 seconds and then set Enabled to true, the count starts at the time Enabled is set. If you reset the interval to 10 seconds when count is 3 seconds, the Elapsed event is raised for the first time 13 seconds after Enabled was set to true.

If the SynchronizingObject property is a null reference (Nothing in Visual Basic), 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. In this situation, the event handler should be reentrant.

NoteNote

The event-handling method might run on one thread at the same time that another thread calls the Stop method or sets the Enabled property to false. This might result in the Elapsed event being raised after the timer is stopped. The example code for the Stop method shows one way to avoid this race condition.

Even if SynchronizingObject is not a null reference (Nothing in Visual Basic), 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 the .NET Framework.

The following code example sets up an event handler for the Timer.Elapsed event, creates a timer, and starts the timer. The event handler displays the SignalTime property each time it is raised.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2016 Microsoft