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

Explictly jump off the main thread before serializing data to call Razor #77321

Merged

Conversation

davidwengier
Copy link
Member

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2268495 ( AB#2268495 but I don't think that works any more 😔)

@davidwengier davidwengier requested a review from a team as a code owner February 23, 2025 21:30
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 23, 2025
@davidwengier davidwengier merged commit 796756b into dotnet:main Feb 26, 2025
25 checks passed
@davidwengier davidwengier deleted the ExplicitlyGetOffTheMainThread branch February 26, 2025 01:17
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Feb 26, 2025
{
// The LSP server will dispose us when the server exits, but VS could decide to activate us later.
// If a new instance of the server is created, a new instance of this class will be created and the
// UIContext will already be active, so this method will be immediately called on the new instance.
if (cancellationToken.IsCancellationRequested) return;

await TaskScheduler.Default.SwitchTo(alwaysYield: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SwitchTo(alwaysYield: true);

Just so I'm clear, the SwitchTo isn't necessary as the concern is about leaving the main thread, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, or maybe you just don't want to block the calling thread, even if it's a threadpool thread. I see.

Copy link
Member Author

@davidwengier davidwengier Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary in the real world, but in theory the UI context could have been activated before we got here (in future if the conditions for the context change), or we could be in VS Code (in future) and I thought getting out of the way of the LSP servers initialize handler is probably kind regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants