From a1db7de67b10f041e913e3bb6093e0bee49caa74 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Mon, 29 Aug 2022 13:30:16 -0700 Subject: [PATCH] Fix potential deadlock if we are previewing a rename change IPreviewDialogService.PreviewChanges does COM calls under the covers, so we need to be on the UI thread for it. --- src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs index b37cb1cedc165..c33ad133486bf 100644 --- a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs +++ b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs @@ -804,6 +804,8 @@ private async Task CommitCoreAsync(IUIThreadOperationContext operationContext, b { var previewService = _workspace.Services.GetService(); + // The preview service needs to be called from the UI thread, since it's doing COM calls underneath. + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); newSolution = previewService.PreviewChanges( string.Format(EditorFeaturesResources.Preview_Changes_0, EditorFeaturesResources.Rename), "vs.csharp.refactoring.rename",