-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Right now disposing a CancellationTokenRegistration will wait for pending callbacks to run if it's disposed on a separate thread from the callback itself. This can cause deadlocks for e.g.:
It would be nice to have a way to disable the blocking on dispose. It might require an API change.
/cc @stephentoub
EDIT 6/29/2018 from stephentoub:
This is the proposed method to be added to CancellationTokenRegistration:
public struct CancellationTokenRegistration
{
public bool Unregister();
...
}We can separately have a discussion about adding a DisposeAsync when the corresponding interface comes along, but we know we can use this API and use it now (it's already there, just not public), and it has a different purpose than a DisposeAsync would. The semantics here are simply that whereas Dispose unregisters and then if the callback is currently running waits for it, this API just unregisters.