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

Stay on the UI thread if it's blocked waiting for us #64813

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ public async Task<VisualStudioProject> CreateAndAddToWorkspaceAsync(

var vsixAnalyzerProvider = await _vsixAnalyzerProviderFactory.GetOrCreateProviderAsync(cancellationToken).ConfigureAwait(false);

// Following can be off the UI thread.
await TaskScheduler.Default;
// The rest of this method can be ran off the UI thread. We'll only switch though if the UI thread isn't already blocked -- the legacy project
// system creates project synchronously, and during solution load we've seen traces where the thread pool is sufficiently saturated that this
// switch can't be completed quickly. For the rest of this method, we won't use ConfigureAwait(false) since we're expecting VS threading
// rules to apply.
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
if (!_threadingContext.JoinableTaskContext.IsMainThreadBlocked())
{
await TaskScheduler.Default;
}

// From this point on, we start mutating the solution. So make us non cancellable.
cancellationToken = CancellationToken.None;
Expand Down Expand Up @@ -144,14 +151,16 @@ await _visualStudioWorkspaceImpl.ApplyChangeToWorkspaceAsync(w =>
{
w.OnProjectAdded(projectInfo);
}
}).ConfigureAwait(false);
});
Copy link
Member

Choose a reason for hiding this comment

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

would prefer an explicit ConfigureAwait(true) here.


// Ensure that other VS contexts get accurate information that the UIContext for this language is now active.
// This is not cancellable as we have already mutated the solution.
await _visualStudioWorkspaceImpl.RefreshProjectExistsUIContextForLanguageAsync(language, CancellationToken.None).ConfigureAwait(false);
await _visualStudioWorkspaceImpl.RefreshProjectExistsUIContextForLanguageAsync(language, CancellationToken.None);
Copy link
Member

Choose a reason for hiding this comment

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

would prefer an explicit ConfigureAwait(true) here.


return project;

#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

static Guid GetSolutionSessionId()
{
var dataModelTelemetrySession = TelemetryService.DefaultSession;
Expand Down