Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateLinkedTokenSource: How to avoid dead code

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?

like image 372
Josh Avatar asked Feb 12 '26 17:02

Josh


1 Answers

To summarize the solution from the two comments: There is an open Roslyn Issue and the warning can safely be ignored

like image 167
Josh Avatar answered Feb 15 '26 11:02

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!