-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
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:
runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/Timers/Timer.cs
Lines 289 to 292 in db5dd99
| 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:
runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/Timers/Timer.cs
Lines 163 to 167 in db5dd99
| _interval = value; | |
| if (_timer != null) | |
| { | |
| UpdateTimer(); | |
| } |
runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/Timers/Timer.cs
Lines 78 to 82 in db5dd99
| _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.