Skip to content

System.Timers.Timer may activate repeating timer in a way in which Stop() would not stop it #33119

@kouvel

Description

@kouvel

When a non-repeating timer ticks, the _enabled field is set instead of the Enabled property here, which does not null out the internal timer:

if (!_autoReset)
{
_enabled = false;
}

Then, when the Interval or AutoReset properties are set, the timer is reactivated because it does not check whether the timer is enabled:

_interval = value;
if (_timer != null)
{
UpdateTimer();
}

_autoReset = value;
if (_timer != null)
{
UpdateTimer();
}

Also, along with reactivating the timer the _enabled field is not set even though the timer is now enabled, and Stop() would not stop the timer because it's already not enabled.

Maybe the original intention was to set the Enabled property to false upon tick, such that timer != null would also imply that the timer is enabled. It would be a breaking change to fix that part, but probably at least when the timer is activated the _enabled field can also be updated such that it reflects the correct state.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions