System.Timers.Timer.Enabled Property

Gets or sets a value indicating whether the System.Timers.Timer should raise the Timer.Elapsed event.

Syntax

[System.ComponentModel.Category("Behavior")]
[System.ComponentModel.DefaultValue(false)]
[System.Timers.TimersDescription("Indicates whether the timer is enabled to fire events at a defined interval.")]
public bool Enabled { get; set; }

Value

Boolean true if this timer is enabled, or boolean false if this timer is disabled.

Remarks

Setting Timer.Enabled to true is the same as calling Timer.Start, while setting Timer.Enabled to false is the same as calling Timer.Stop.

Note:

The signal to raise the Timer.Elapsed event is always queued for execution on a System.Threading.ThreadPool thread. This might result in the Timer.Elapsed event being raised after the Timer.Enabled property is set to false. The code example for the Timer.Stop method shows one way to work around this race condition.

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

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

Note:

Some visual designers, such as those in Microsoft Visual Studio, set the Timer.Enabled property to true when inserting a new System.Timers.Timer.

Requirements

Namespace: System.Timers
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0