You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When registering with a CancellationToken, a common pattern is to then store the resulting CancellationTokenRegistration onto some object for later disposal when the associated asynchronous operation completes. It's also common to store the original CancellationToken, so that it can, for example, be passed to TaskCompletionSource.TrySetCanceled. But having to store the CancellationToken in addition to the CancellationTokenRegistration should be unnecessary, as the registration already knows with which CancellationToken it's associated... it just doesn't expose that information. We should expose it.
do you think your proposal will affect that issue?
I believe they are unrelated in both design and implementation. This is purely about exposing from CancellationTokenRegistration information we already have in order to not have to carry that information around separately. The other proposal you mention is about adding new functionality to CancellationTokenSource, such that the implementation can queue the invocation of any registered handlers if any exist.
When registering with a CancellationToken, a common pattern is to then store the resulting CancellationTokenRegistration onto some object for later disposal when the associated asynchronous operation completes. It's also common to store the original CancellationToken, so that it can, for example, be passed to TaskCompletionSource.TrySetCanceled. But having to store the CancellationToken in addition to the CancellationTokenRegistration should be unnecessary, as the registration already knows with which CancellationToken it's associated... it just doesn't expose that information. We should expose it.
This property now exists, it's just internal:
https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Threading/CancellationTokenRegistration.cs#L44
We should simply make it public.
This will allow us to shrink by a reference-sized field several objects that store the CT in addition to the CTR.
The text was updated successfully, but these errors were encountered: