Skip to content

Commit

Permalink
Move off UI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed May 14, 2024
1 parent 60cc971 commit 1a2f73f
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.VisualStudio.Settings;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Settings;
using Microsoft.VisualStudio.Threading;
using Roslyn.Utilities;
using VSShell = Microsoft.VisualStudio.Shell;

Expand Down Expand Up @@ -70,15 +71,27 @@ public VisualStudioSymbolSearchService(

public void Dispose()
{
ISymbolSearchUpdateEngine? updateEngine;
using (_gate.DisposableWait())
// Once we're disposed, swap out our engine with a no-op one so we don't try to do any more work, and dispose of
// our connection to the OOP server so it can be cleaned up.
//
// Kick off a Task for this so we don't block MEF from proceeding (as it will be calling us on the UI thread).
_ = DisposeAsync();
return;

async Task DisposeAsync()
{
// Once we're disposed, swap out our engine with a no-op one so we don't try to do any more work.
updateEngine = _lazyUpdateEngine;
_lazyUpdateEngine = SymbolSearchUpdateNoOpEngine.Instance;
}
// Make sure we get off the UI thread so that Dispose can return immediately.
await TaskScheduler.Default;

updateEngine?.Dispose();
ISymbolSearchUpdateEngine? updateEngine;
using (await _gate.DisposableWaitAsync().ConfigureAwait(false))
{
updateEngine = _lazyUpdateEngine;
_lazyUpdateEngine = SymbolSearchUpdateNoOpEngine.Instance;
}

updateEngine?.Dispose();
}
}

protected override async Task EnableServiceAsync(CancellationToken cancellationToken)
Expand Down

0 comments on commit 1a2f73f

Please sign in to comment.