Skip to content

Commit

Permalink
Merge pull request #58351 from CyrusNajmabadi/componentModelBG
Browse files Browse the repository at this point in the history
Swithc to acquiring the component model on a BG thread.
  • Loading branch information
CyrusNajmabadi authored Dec 15, 2021
2 parents d6f231d + 4bceea8 commit b246a00
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using Roslyn.Utilities;
using Task = System.Threading.Tasks.Task;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
Expand All @@ -41,6 +42,9 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
{
await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);

await TaskScheduler.Default;
_componentModel_doNotAccessDirectly = await this.GetServiceAsync<SComponentModel, IComponentModel>(throwOnFailure: true).ConfigureAwait(false);

await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var shell = (IVsShell7)await GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true);
Expand Down Expand Up @@ -106,11 +110,7 @@ internal IComponentModel ComponentModel
{
get
{
ThreadHelper.ThrowIfNotOnUIThread();

if (_componentModel_doNotAccessDirectly == null)
_componentModel_doNotAccessDirectly = (IComponentModel)GetService(typeof(SComponentModel));

Contract.ThrowIfNull(_componentModel_doNotAccessDirectly);
return _componentModel_doNotAccessDirectly;
}
}
Expand Down

0 comments on commit b246a00

Please sign in to comment.