vs-threading
vs-threading copied to clipboard
VSTHRD002: Analyzer unable to detect synchronous wait call in action parameter when the wrapping function return Task
Bug description
Analyzer rule VSTHRD002 is unable to detect synchronous wait call in action parameter when the wrapping function return Task.
Repro steps
Use below code snippet:
using System;
using System.Linq;
using System.Threading.Tasks;
namespace vsthreadtest
{
class Program
{
static async Task Main(string[] args)
{
await FooAsync();
Foo1();
}
public static Task FooAsync()
{
Task.Delay(TimeSpan.FromSeconds(5)).Wait();
Enumerable.Range(1, 10).ToList().ForEach(i => { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); });
return Task.CompletedTask;
}
public static void Foo1()
{
Enumerable.Range(1, 10).ToList().ForEach(i => { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); });
}
}
}
Expected behavior
All Task.Delay(TimeSpan.FromSeconds(5)).Wait() calls should be detected by VSTHRD002
Actual behavior
Enumerable.Range(1, 10).ToList().ForEach(i => { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); }) in FooAsync is not detected.

- Version used: "Microsoft.VisualStudio.Threading.Analyzers 16.6.13"
- Application (if applicable):
Additional context
I only test the behavior of application targeted "netcoreapp3.1"