Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

[release/2.2] Fix CancellationTokenRegistration.Token after CTS.Dispose #21417

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public void Dispose()
/// registration isn't associated with a token (such as after the registration has been disposed),
/// this will return a default token.
/// </summary>
public CancellationToken Token => _node?.Partition.Source.Token ?? default(CancellationToken);
public CancellationToken Token
{
get
{
CancellationTokenSource.CallbackNode node = _node;
return node != null ?
new CancellationToken(node.Partition.Source) : // avoid CTS.Token, which throws after disposal
default;
}
}

/// <summary>
/// Disposes of the registration and unregisters the target callback from the associated
Expand Down