From 6c4173ff8f966859727ad4989c02638188e78dec Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Thu, 18 Oct 2018 14:13:07 -0700 Subject: [PATCH] Allow NavigationBarController to handle background thread changes We might disconnect/reconnect on background threads now, so be ready for that. --- .../NavigationBar/NavigationBarController.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/Core/Implementation/NavigationBar/NavigationBarController.cs b/src/EditorFeatures/Core/Implementation/NavigationBar/NavigationBarController.cs index 76891ec92c8..7411e2e95e2 100644 --- a/src/EditorFeatures/Core/Implementation/NavigationBar/NavigationBarController.cs +++ b/src/EditorFeatures/Core/Implementation/NavigationBar/NavigationBarController.cs @@ -94,8 +94,6 @@ private void OnWorkspaceRegistrationChanged(object sender, EventArgs e) private void ConnectToWorkspace(Workspace workspace) { - AssertIsForeground(); - // If we disconnected before the workspace ever connected, just disregard if (_disconnected) { @@ -105,8 +103,26 @@ private void ConnectToWorkspace(Workspace workspace) _workspace = workspace; _workspace.WorkspaceChanged += this.OnWorkspaceChanged; - // For the first time you open the file, we'll start immediately - StartModelUpdateAndSelectedItemUpdateTasks(modelUpdateDelay: 0, selectedItemUpdateDelay: 0, updateUIWhenDone: true); + void connectToNewWorkspace() + { + // For the first time you open the file, we'll start immediately + StartModelUpdateAndSelectedItemUpdateTasks(modelUpdateDelay: 0, selectedItemUpdateDelay: 0, updateUIWhenDone: true); + } + + if (IsForeground()) + { + connectToNewWorkspace(); + } + else + { + var asyncToken = _asyncListener.BeginAsyncOperation(nameof(ConnectToWorkspace)); + Task.Run(async () => + { + await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(); + + connectToNewWorkspace(); + }).CompletesAsyncOperation(asyncToken); + } } private void DisconnectFromWorkspace() -- GitLab