File tree Expand file tree Collapse file tree
src/libraries/System.Private.CoreLib/src/System/Threading Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -396,9 +396,21 @@ public bool TryReset()
396396 // to reset it to be infinite so that it won't fire, and then recognize that it could have already
397397 // fired by the time we successfully changed it, and so check to see whether that's possibly the case.
398398 // If we successfully reset it and it never fired, then we can be sure it won't trigger cancellation.
399- bool reset =
400- _timer is not TimerQueueTimer timer ||
401- ( timer . Change ( Timeout . UnsignedInfinite , Timeout . UnsignedInfinite ) && ! timer . _everQueued ) ;
399+ bool reset = false ;
400+ if ( _timer is TimerQueueTimer timer )
401+ {
402+ try
403+ {
404+ reset = timer . Change ( Timeout . UnsignedInfinite , Timeout . UnsignedInfinite ) && ! timer . _everQueued ;
405+ }
406+ catch ( ObjectDisposedException )
407+ {
408+ // Just eat the exception. There is no other way to tell that
409+ // the timer has been disposed, and even if there were, there
410+ // would not be a good way to deal with the observe/dispose
411+ // race condition.
412+ }
413+ }
402414
403415 if ( reset )
404416 {
You can’t perform that action at this time.
0 commit comments