Skip to content

[Engineering task] Update threading analyzers #4698

@pmaytak

Description

@pmaytak

Task type

Best practices

Description

Need to update the threading analyzers to match best practices.
https://github.com/microsoft/vs-threading/blob/main/docfx/analyzers/index.md

  • Update VSTHR* rules in the editor config:
    dotnet_diagnostic.VSTHRD200.severity = error
    # Use .ConfigureAwait(bool)
    dotnet_diagnostic.VSTHRD111.severity = error
    # Avoid async void methods
    dotnet_diagnostic.VSTHRD100.severity = warning
    # Critical Threading Rules
    # Avoid legacy thread switching methods
    dotnet_diagnostic.VSTHRD001.severity = warning
    # Avoid problematic synchronous waits
    dotnet_diagnostic.VSTHRD002.severity = none
    # Avoid awaiting foreign Tasks
    dotnet_diagnostic.VSTHRD003.severity = none
    # Await SwitchToMainThreadAsync
    dotnet_diagnostic.VSTHRD004.severity = error
    # Invoke single-threaded types on Main thread
    dotnet_diagnostic.VSTHRD010.severity = warning
    # Use AsyncLazy<T>
    dotnet_diagnostic.VSTHRD011.severity = none #error requires the use of Microsoft.VisualStudio.Threading to get access to the AsyncLazy<T> type
    # Provide JoinableTaskFactory where allowed
    dotnet_diagnostic.VSTHRD012.severity = warning
    # Compiler warnings that trigger SDL
    dotnet_diagnostic.CS0618.severity = error
    # General Threading Rules
    # VSTHRD103: Call async methods when in an async method
    dotnet_diagnostic.VSTHRD103.severity = none
    # VSTHRD105: use current context
    dotnet_diagnostic.VSTHRD105.severity = none
    # VSTHRD001: use JoinableTaskFactory (this is part of a different package - MSAL cannot use it)
    dotnet_diagnostic.VSTHRD001.severity = none
  • Remove this rule from tests .editorconfig:
    dotnet_diagnostic.VSTHRD100.severity = none
  • Suppress any other irrelevant rules in tests .editorconfig.
  • Fix any errors or suppress them in the GlobalSuppressions file.
  • Ignore all the rules for json folder.

See some work done in pmaytak/threading-analyzers.

Solution

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Committed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions