@@ -19,7 +19,6 @@ internal sealed class ActiveHandlerTrackingEntry : IDisposable
1919 private Timer ? _timer ;
2020 private TimerCallback ? _callback ;
2121 // States for the handler tracking entry
22- private const int NotDisposed = 0 ;
2322 private const int Disposed = 1 ;
2423 private const int Expired = 2 ;
2524 private int _disposed ;
@@ -48,7 +47,7 @@ public ActiveHandlerTrackingEntry(
4847
4948 public void StartExpiryTimer ( TimerCallback callback )
5049 {
51- if ( Interlocked . CompareExchange ( ref _disposed , _disposed , _disposed ) != NotDisposed )
50+ if ( _disposed > 0 )
5251 {
5352 return ;
5453 }
@@ -73,7 +72,7 @@ private void StartExpiryTimerSlow(TimerCallback callback)
7372 lock ( _lock )
7473 {
7574 if ( Volatile . Read ( ref _timerInitialized ) ||
76- Interlocked . CompareExchange ( ref _disposed , _disposed , _disposed ) != NotDisposed )
75+ _disposed > 0 )
7776 {
7877 return ;
7978 }
@@ -87,7 +86,7 @@ private void StartExpiryTimerSlow(TimerCallback callback)
8786 private void Timer_Tick ( )
8887 {
8988 Debug . Assert ( _callback != null ) ;
90- Debug . Assert ( _timer != null || _disposed != NotDisposed ) ;
89+ Debug . Assert ( _timer != null || _disposed > 0 ) ;
9190
9291 lock ( _lock )
9392 {
@@ -96,9 +95,9 @@ private void Timer_Tick()
9695 _timer . Dispose ( ) ;
9796 _timer = null ;
9897
99- // Only invoke the callback if we successfully transition from NotDisposed to Expired
98+ // Only invoke the callback if we successfully transition from 0 to Expired
10099 // This ensures we don't convert to expired if already disposed
101- if ( Interlocked . CompareExchange ( ref _disposed , Expired , NotDisposed ) == NotDisposed )
100+ if ( Interlocked . CompareExchange ( ref _disposed , Expired , 0 ) == 0 )
102101 {
103102 _callback ( this ) ;
104103 }
@@ -117,10 +116,10 @@ public void StopTimer()
117116
118117 public void Dispose ( )
119118 {
120- // Try to transition from NotDisposed to Disposed state
119+ // Try to transition from 0 to Disposed state
121120 // If already in another state (Expired), do nothing further with handlers
122- int oldState = Interlocked . CompareExchange ( ref _disposed , Disposed , NotDisposed ) ;
123- if ( oldState != NotDisposed )
121+ int oldState = Interlocked . CompareExchange ( ref _disposed , Disposed , 0 ) ;
122+ if ( oldState != 0 )
124123 {
125124 // If the entry was already disposed or expired, exit
126125 // If it was expired, the timer has already stopped and
0 commit comments