From 9d2378f282bd728d9d6a212bbdb7e229127e5455 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Sat, 22 Apr 2017 14:09:24 -0700 Subject: [PATCH] Kick off work to the BG to ensure the UI thread doesn't need to block. --- .../AbstractObjectBrowserLibraryManager.cs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs index b486f5a5385..31b4702d354 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs @@ -531,14 +531,13 @@ protected override bool TryExec(Guid commandGroup, uint commandId) var cancellationToken = context.CancellationToken; - // Fire and forget the work to go get references. - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); - var symbol = symbolListItem.ResolveSymbol(compilation); - if (symbol != null) + // Kick off the work to do the actual finding on a BG thread. That way we don' + // t block the calling (UI) thread too long if we happen to do our work on this + // thread. + await Task.Run(async () => { - await AbstractFindUsagesService.FindSymbolReferencesAsync( - context, symbol, project, cancellationToken).ConfigureAwait(false); - } + await FindReferencesAsync(symbolListItem, project, context, cancellationToken).ConfigureAwait(false); + }, cancellationToken).ConfigureAwait(false); // Note: we don't need to put this in a finally. The only time we might not hit // this is if cancellation or another error gets thrown. In the former case, @@ -554,5 +553,16 @@ protected override bool TryExec(Guid commandGroup, uint commandId) { } } + + private static async Task FindReferencesAsync(SymbolListItem symbolListItem, Project project, CodeAnalysis.FindUsages.FindUsagesContext context, CancellationToken cancellationToken) + { + var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var symbol = symbolListItem.ResolveSymbol(compilation); + if (symbol != null) + { + await AbstractFindUsagesService.FindSymbolReferencesAsync( + context, symbol, project, cancellationToken).ConfigureAwait(false); + } + } } } \ No newline at end of file -- GitLab