I try to implement a linked cancellation token and get a warning that the CancellationTokeSource is never null and dead code can be avoided.
public void Foo(CancellationToken cancellationToken , TimeSpan t) {
using CancellationTokenSource timeout = new CancellationTokenSource(t);
using CancellationTokenSource combined = CancellationTokenSource
.CreateLinkedTokenSource(
timeout.Token,
cancellationToken);
bar(combined.Token);
}
To be more specific: I get the CA1508 warning which suggests removing the conditions to avoid dead code. But the thing is, I don't see any conditions here. Am I missing something or can this warning be safely ignored?
To summarize the solution from the two comments: There is an open Roslyn Issue and the warning can safely be ignored
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With