microsoft / microsoft/vs-threading
VSTHRD004 incorrectly fires on results of methods are returned to the caller
Open
Nobody has claimed this yet.
analyzers
- Dominant language
- C#
- Stars
- 1k
- Forks
- 160
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 28
Description
Bug description
VSTHRD004 incorrectly fires on results of methods are returned to the caller.
Repro steps
public static JoinableTaskFactory.MainThreadAwaitable SwitchToUIThread(this IProjectThreadingService threading, CancellationToken cancellationToken)
{
return threading.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); <!-- VSTHRD004
}
Expected behavior
VSTHRD004 not to fire because the result is returned to the caller.
Actual behavior
Severity Code Description File Project Line Suppression State
Error VSTHRD004 Calls to JoinableTaskFactory.SwitchToMainThreadAsync() must be awaited. E:\project-system2\src\Microsoft.VisualStudio.ProjectSystem.Managed\ProjectSystem\ThreadingExtensions.cs Microsoft.VisualStudio.ProjectSystem.Managed 30 Active
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the VSTHRD004 diagnostic logic and the reproduction in ThreadingExtensions.cs, where SwitchToMainThreadAsync is returned from SwitchToUIThread. Run the shown C# case and confirm that returning the awaitable no longer produces VSTHRD004 while direct unawaited calls remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100