Showing the changes to Source/Libraries/GSF.Core.Shared/Threading/SharedTimer.cs (1 of 1 file). Show all
Unified · Split
| @@ -85,7 +85,7 @@ namespace GSF.Threading · 84 unmodified lines | |||
| 85 | [EditorBrowsable(EditorBrowsableState.Never)] | 85 | [EditorBrowsable(EditorBrowsableState.Never)] |
| 86 | internal SharedTimer(SharedTimerScheduler scheduler, int interval = 100) | 86 | internal SharedTimer(SharedTimerScheduler scheduler, int interval = 100) |
| 87 | { | 87 | { |
| 88 | if ((object)scheduler == null) | 88 | if (scheduler == null) |
| 89 | throw new ArgumentNullException(nameof(scheduler)); | 89 | throw new ArgumentNullException(nameof(scheduler)); |
| 90 | 90 | ||
| 91 | if (scheduler.IsDisposed) | 91 | if (scheduler.IsDisposed) |
| @@ -118,10 +118,7 @@ namespace GSF.Threading · 26 unmodified lines | |||
| 118 | /// </returns> | 118 | /// </returns> |
| 119 | public bool AutoReset | 119 | public bool AutoReset |
| 120 | { | 120 | { |
| 121 | get | 121 | get => m_autoReset; |
| 122 | { | ||
| 123 | return m_autoReset; | ||
| 124 | } | ||
| 125 | set | 122 | set |
| 126 | { | 123 | { |
| 127 | if (m_autoReset == value) | 124 | if (m_autoReset == value) |
| @@ -129,11 +126,11 @@ namespace GSF.Threading · 1 unmodified line | |||
| 129 | 126 | ||
| 130 | m_autoReset = value; | 127 | m_autoReset = value; |
| 131 | 128 | ||
| 132 | if (value && m_enabled) | 129 | if (!m_autoReset || !m_enabled) |
| 133 | { | 130 | return; |
| 134 | m_registeredCallback?.Clear(); | 131 | |
| 135 | m_registeredCallback = m_scheduler.RegisterCallback(m_interval, m_callback); | 132 | m_registeredCallback?.Clear(); |
| 136 | } | 133 | m_registeredCallback = m_scheduler.RegisterCallback(m_interval, m_callback); |
| 137 | } | 134 | } |
| 138 | } | 135 | } |
| 139 | 136 | ||
| @@ -146,18 +143,16 @@ namespace GSF.Threading · 6 unmodified lines | |||
| 146 | /// </returns> | 143 | /// </returns> |
| 147 | public bool Enabled | 144 | public bool Enabled |
| 148 | { | 145 | { |
| 149 | get | 146 | get => m_enabled; |
| 150 | { | ||
| 151 | return m_enabled; | ||
| 152 | } | ||
| 153 | set | 147 | set |
| 154 | { | 148 | { |
| 155 | if (m_disposed) | ||
| 156 | throw new ObjectDisposedException(GetType().FullName); | ||
| 157 | |||
| 158 | if (m_enabled == value) | 149 | if (m_enabled == value) |
| 159 | return; | 150 | return; |
| 160 | 151 | ||
| 152 | // Check dispose after checking if there was an actual state change (in case Stop or Close is called after Dispose) | ||
| 153 | if (m_disposed) | ||
| 154 | throw new ObjectDisposedException(GetType().FullName); | ||
| 155 | |||
| 161 | m_enabled = value; | 156 | m_enabled = value; |
| 162 | 157 | ||
| 163 | if (!m_enabled) | 158 | if (!m_enabled) |
| @@ -177,10 +172,7 @@ namespace GSF.Threading · 13 unmodified lines | |||
| 177 | /// </remarks> | 172 | /// </remarks> |
| 178 | public int Interval | 173 | public int Interval |
| 179 | { | 174 | { |
| 180 | get | 175 | get => m_interval; |
| 181 | { | ||
| 182 | return m_interval; | ||
| 183 | } | ||
| 184 | set | 176 | set |
| 185 | { | 177 | { |
| 186 | if (value <= 0) | 178 | if (value <= 0) |
| @@ -191,11 +183,11 @@ namespace GSF.Threading · 4 unmodified lines | |||
| 191 | 183 | ||
| 192 | m_interval = value; | 184 | m_interval = value; |
| 193 | 185 | ||
| 194 | if (m_enabled) | 186 | if (!m_enabled) |
| 195 | { | 187 | return; |
| 196 | m_registeredCallback?.Clear(); | 188 | |
| 197 | m_registeredCallback = m_scheduler.RegisterCallback(m_interval, m_callback); | 189 | m_registeredCallback?.Clear(); |
| 198 | } | 190 | m_registeredCallback = m_scheduler.RegisterCallback(m_interval, m_callback); |
| 199 | } | 191 | } |
| 200 | } | 192 | } |
| 201 | 193 | ||
| @@ -206,10 +198,7 @@ namespace GSF.Threading · 4 unmodified lines | |||
| 206 | /// <summary> | 198 | /// <summary> |
| 207 | /// Stops the timer. | 199 | /// Stops the timer. |
| 208 | /// </summary> | 200 | /// </summary> |
| 209 | public void Close() | 201 | public void Close() => Enabled = false; |
| 210 | { | ||
| 211 | Enabled = false; | ||
| 212 | } | ||
| 213 | 202 | ||
| 214 | /// <summary> | 203 | /// <summary> |
| 215 | /// Stops the timer and prevents reuse of the class. | 204 | /// Stops the timer and prevents reuse of the class. |
| @@ -223,18 +212,12 @@ namespace GSF.Threading · 7 unmodified lines | |||
| 223 | /// <summary> | 212 | /// <summary> |
| 224 | /// Starts raising the <see cref="Elapsed" /> event by setting <see cref="Enabled" /> to <c>true</c>. | 213 | /// Starts raising the <see cref="Elapsed" /> event by setting <see cref="Enabled" /> to <c>true</c>. |
| 225 | /// </summary> | 214 | /// </summary> |
| 226 | public void Start() | 215 | public void Start() => Enabled = true; |
| 227 | { | ||
| 228 | Enabled = true; | ||
| 229 | } | ||
| 230 | 216 | ||
| 231 | /// <summary> | 217 | /// <summary> |
| 232 | /// Stops raising the <see cref="Elapsed"/> event by setting <see cref="Enabled" /> to <c>false</c>. | 218 | /// Stops raising the <see cref="Elapsed"/> event by setting <see cref="Enabled" /> to <c>false</c>. |
| 233 | /// </summary> | 219 | /// </summary> |
| 234 | public void Stop() | 220 | public void Stop() => Enabled = false; |
| 235 | { | ||
| 236 | Enabled = false; | ||
| 237 | } | ||
| 238 | 221 | ||
| 239 | /// <summary> | 222 | /// <summary> |
| 240 | /// Callback from <see cref="SharedTimerScheduler"/>. | 223 | /// Callback from <see cref="SharedTimerScheduler"/>. |