If I have CancellationTokens which were previously returned by CancellationTokenSource.Token { get; } is it safe to call CancellationTokenSource Dispose()? (I'm worried that it invalidates the CancellationTokens.)
If it's not safe can I just rely on the CancellationTokenSource finalizer?
That's not (documented to be) safe but it's also not necessary. You can store the token away and safely use it even after disposing the CancellationTokenSource
. Just don't call CancellationTokenSource.Token
anymore. Use the token that you obtained before disposing.
Whether you need to dispose a CancellationTokenSource
at all is a different question. There are different cases and different opinions. There's a thread about that but the answers are dubious. Use with care.