Skip to content

Commit 7913094

Browse files
committed
Quick fix of #60182
1 parent 383a479 commit 7913094

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)