Skip to content

VSTHRD002: Analyzer unable to detect synchronous wait call in action parameter when the wrapping function return Task #632

Closed

Description

@t-bzhan

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.

image

  • Version used: "Microsoft.VisualStudio.Threading.Analyzers 16.6.13"
  • Application (if applicable):

Additional context

I only test the behavior of application targeted "netcoreapp3.1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions