Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSTHRD010 warning despite call to JoinableTaskFactory.SwitchToMainThreadAsync #1295

Closed
kfam98 opened this issue Mar 29, 2024 · 2 comments
Closed

Comments

@kfam98
Copy link

kfam98 commented Mar 29, 2024

Bug description

I pushed the threading version for a certain project. Now, the warning VSTHRD010 is coming up for certain parts of code despite the call to JoinableTaskFactory.SwitchToMainnThreadAsync.

Repro steps

        public static async Task<bool> TestMethod(JoinableTaskFactory jtf)
        {
            await jtf.SwitchToMainThreadAsync(VsShellUtilities.ShutdownToken);


#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
            // do something that requires main thread
#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
        }

Expected behavior

No warning should appear.

Actual behavior

Warning appeared, and we have to suppress the warning. Despite switching to main thread.

  • Version used: 17.10.41
@kfam98 kfam98 changed the title VSTHRD010 warning despite call to JoinableTaskFactory.SwitchToMainnThreadAsync VSTHRD010 warning despite call to JoinableTaskFactory.SwitchToMainThreadAsync Mar 29, 2024
@AArnott
Copy link
Member

AArnott commented Apr 6, 2024

I agree this shouldn't be happening. Your sample code is about as simple as it gets for what should work however. In fact it's equivalent to this test we have:

async Task F() {
await jtf.SwitchToMainThreadAsync();
IVsSolution sln = null;
sln.SetProperty(1000, null);
}

So I can only imagine there is something else about your repro that is important to understand why it's broken. Any ideas what that might be?

@AArnott
Copy link
Member

AArnott commented Sep 27, 2024

17.12.19 no longer repros this, in a case that we had internally that seemed to repro the same issue.

@AArnott AArnott closed this as completed Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants