Make TimeProvider Delay Continuations Synchronously - #90489
Conversation
…Tasks/TimeProviderTaskExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
|
Tagging subscribers to this area: @dotnet/area-system-datetime Issue DetailsFixes #85326 The TimeProvider in .NET 8.0 offers Task Delay functionality, and this functionality is also accessible in earlier versions using the System.Bcl.TimeProvider library. When invoked within the .NET 8.0 runtime, it generates a Task like using DelayPromise, configured with a state flags value of 0x07000400. This setting signifies that the Task's continuation will be executed synchronously. Once the Delay duration elapses, the RunContinuations function is triggered. Within this process, a check is performed (at this point), leading to the synchronous execution of the task continuation due to the absence of the In cases where we operate on earlier runtime versions, we explicitly enable the
|
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Fixes #85326
The TimeProvider in .NET 8.0 offers Task Delay functionality, and this functionality is also accessible in earlier versions using the System.Bcl.TimeProvider library. When invoked within the .NET 8.0 runtime, it generates a Task like using DelayPromise, configured with a state flags value of 0x07000400. This setting signifies that the Task's continuation will be executed synchronously. Once the Delay duration elapses, the RunContinuations function is triggered. Within this process, a check is performed (at this point), leading to the synchronous execution of the task continuation due to the absence of the
TaskCreationOptions.RunContinuationsAsynchronouslyflag.In cases where we operate on earlier runtime versions, we explicitly enable the
TaskCreationOptions.RunContinuationsAsynchronouslyflag, which modifies the behavior of task continuations compared to .NET 8.0. To ensure consistent behavior with .NET 8.0, the recommended solution is to refrain from setting theTaskCreationOptions.RunContinuationsAsynchronouslyflag when executing on earlier runtime versions.