Is the hadhcode returned by CancellationTokenSource.GetHashCode()
constant for the duration of the token instance ?
That is is it safe to hold cancellation tokens in ie a HashSet ?
ImmutableHashSet<CancellationTokenSource> TokensSet = new();
TokensSet = TokensSet.Add(myToken);
CodePudding user response:
The class CancellationTokenSource
does not override the GetHashCode()
method, so that the implementation of Object.GetHashCode()
is used. This means that the hash code remains the same over the whole lifetime of the instance.