Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit c9efb13

Browse files
committed
fix synchronization event sent from Sourcetrail via socket was handled in non-ui thread
1 parent 01fac66 commit c9efb13

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

SourcetrailExtension/SourcetrailExtensionPackage.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -231,7 +231,7 @@ protected async override System.Threading.Tasks.Task InitializeAsync(Cancellatio
231231
_menuItemSetActiveToken = new MenuCommand(MenuItemCallback, setActiveTokenCommandID);
232232
_menuItemCreateCdb = new MenuCommand(MenuItemCallback, createCdbID);
233233
_menuItemOpenLogDir = new MenuCommand(MenuItemCallback, openLogDirID);
234-
234+
235235
_menuItemSetActiveToken.Enabled = false;
236236
_menuItemCreateCdb.Enabled = false;
237237
_menuItemOpenLogDir.Enabled = true;
@@ -457,13 +457,22 @@ private void OnNetworkReadCallback(string message)
457457
Logging.Logging.LogInfo("Trying to set cursor position to line " + cursorPosition.LineNumber + ", column " + cursorPosition.ColumnNumber + " in file \"" + cursorPosition.FilePath + "\"");
458458

459459
cursorPosition.ColumnNumber += 1; // VS counts columns starting at 1, sourcetrail starts at 0
460-
DTE dte = (DTE)GetService(typeof(DTE));
461-
if (Utility.FileUtility.OpenSourceFile(dte, cursorPosition.FilePath))
462-
{
463-
Utility.FileUtility.GoToLine(dte, cursorPosition.LineNumber, cursorPosition.ColumnNumber);
464460

465-
Utility.SystemUtility.GetWindowFocus();
466-
}
461+
ThreadHelper.JoinableTaskFactory.Run(
462+
async delegate
463+
{
464+
// Switch to main thread
465+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
466+
467+
DTE dte = (DTE)GetService(typeof(DTE));
468+
if (Utility.FileUtility.OpenSourceFile(dte, cursorPosition.FilePath))
469+
{
470+
Utility.FileUtility.GoToLine(dte, cursorPosition.LineNumber, cursorPosition.ColumnNumber);
471+
472+
Utility.SystemUtility.GetWindowFocus();
473+
}
474+
}
475+
);
467476
}
468477
}
469478
else if(messageType == Utility.NetworkProtocolUtility.MESSAGE_TYPE.CREATE_CDB)
@@ -576,7 +585,7 @@ private void CreateCompilationDatabase(DTE dte)
576585

577586
window.UpdateGUI();
578587
window._onCreateProject = OnCreateProject;
579-
588+
580589
window.ShowDialog();
581590
}
582591
}

0 commit comments

Comments
 (0)