Microsoft.CodeAnalysis.FxCopAnalyzers
Example: v2.6.2
CA2008: Do not create tasks without passing a TaskScheduler
Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear.
I could not find a documentation page.
Use TaskFactory.StartNew as method group parameter.
public static class Program
{
public static async Task Main(string[] args)
{
var taskFactory = new TaskFactory();
var actions = new Action[] { Console.WriteLine, Console.WriteLine };
await Task.WhenAll(actions.Select(taskFactory.StartNew)).ConfigureAwait(false);
}
}
Waring is displayed.
No warning is displayed.
I just stumpled upon this "behaivor". It's not important for me I just wanted to report it for documentation reasons.
Amusingly, our version of this analyzer (VSTHRD105) got the same feedback.
Oh wait, that's not the same issue. You're arguing that the diagnostic should appear with a method group. But per the issue I linked to, in this particular example case (of using a custom TaskFactory) it may be good to suppress such a diagnostic.
@AArnott
Oh wait, that's not the same issue. You're arguing that the diagnostic should appear with a method group.
Yep but I think this one could be the same.
CA2008 Do not create tasks without passing a TaskScheduler should not appear
Most helpful comment
@AArnott
Yep but I think this one could be the same.
CA2008 Do not create tasks without passing a TaskScheduler should not appear