Description
A full description of the issue is here: #60180
Reproduction Steps
- Create CTS
- Call
CancelAfter with very small timeout (1-10 milliseconds)
- Call
TryReset concurrently with CancelAfter
Expected behavior
TryReset should normally handle the concurrency with timer cancellation and return true/false.
Actual behavior
System.ObjectDisposedException : Cannot access a disposed object.
Stack Trace:
at System.Threading.TimerQueueTimer.Change(UInt32 dueTime, UInt32 period)
at System.Threading.CancellationTokenSource.TryReset()
Regression?
No, TryReset is introduced in .NET 6.
Known Workarounds
Do not use TryReset at all and re-create CTS every time when needed.
or
catch ObjectDisposedException by the caller:
static bool TryResetSafe(CancellationTokenSource source)
{
try
{
return source.TryReset();
}
catch (ObjectDisposedException)
{
return false;
}
}
Configuration
The environment is not relevant. .NET SDK version is 6.0.100-rc.1.21458.32
Other information
No response
Description
A full description of the issue is here: #60180
Reproduction Steps
CancelAfterwith very small timeout (1-10 milliseconds)TryResetconcurrently withCancelAfterExpected behavior
TryResetshould normally handle the concurrency with timer cancellation and return true/false.Actual behavior
Regression?
No,
TryResetis introduced in .NET 6.Known Workarounds
Do not use
TryResetat all and re-create CTS every time when needed.or
catch
ObjectDisposedExceptionby the caller:Configuration
The environment is not relevant. .NET SDK version is
6.0.100-rc.1.21458.32Other information
No response