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

Remove GetService(...) calls from VS MEF importing constructors #10168

Conversation

DustinCampbell
Copy link
Member

We observed a hang during solution load because VisualStudioEditorDocumentManager retrieves the IVsRunningDocumentTable service in its constructor. When this constructor is called on a background thread, it results in an implicit marshal to the UI thread in order to retrieve the service and QI for its COM interface. This change fixes that issue delaying the request for IVsRunningDocumentTable until it is needed and running on the UI thread.

In addition, VisualStudioFileChangeTrackerFactory had a similar issue but with IVsAsyncFileChangeEx. Because IFileChangeTrackerFactory is imported by VisualStudioEditorDocumentManager, I've fixed this service as well.

The `VisualStudioEditorDocumentManager` listens for running document
table events and was retrieving the `IVsRunningDocumentTable` in its
constructor. Because this is an `[ImportingConstructor]` it will
almost certain be called on the thread pool and will implicitly
marshal to the UI thread to perform a QI as part of retrieving the
service. This can cause a hang if the UI thread is tied up with other
work, such as when a solution is loaded.

This change avoids retrieving the running doc table service until its
needed and we are already running on the UI thread.
`VisualStudioFileChangeTrackerFactory` retrieves an `IVsAsyncFileChangeEx` service in its constructor. Because this is an `[ImportingConstructor]` it will likely be called on the thread pool and implicitly marshal to the UI thread to perform a QI as part of retrieving the service. This can cause a hang if the UI thread is tied up with other work, such as when a solution is loaded.

This change avoids retrieving `IVsAsyncFileChangeEx` until its needed. This does block on retrieving the service. However, avoiding that will require a more substantial change that I'll follow up with on `main`.
@DustinCampbell DustinCampbell requested a review from a team as a code owner March 26, 2024 18:15
@DustinCampbell DustinCampbell merged commit a7c635f into dotnet:release/dev17.10 Mar 26, 2024
12 checks passed
@DustinCampbell DustinCampbell deleted the fix-getservice-on-background branch March 26, 2024 19:21
@RikkiGibson RikkiGibson added this to the 17.10 P3 milestone Mar 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

Successfully merging this pull request may close these issues.

4 participants