Skip to content

Commit 800068b

Browse files
Use UI thread for setting clipboard text - fixes #457
1 parent 6513167 commit 800068b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Vsix/CodeConversion.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,20 @@ await _joinableTaskFactory.RunAsync(async () => {
6666
});
6767

6868
if ((await GetOptions()).CopyResultToClipboardForSingleDocument) {
69-
Clipboard.SetText(conversionResult.ConvertedCode ?? conversionResult.GetExceptionsAsString());
69+
await SetClipboardTextOnUiThreadAsync(conversionResult.ConvertedCode ?? conversionResult.GetExceptionsAsString());
7070
await _outputWindow.WriteToOutputWindowAsync(Environment.NewLine + "Conversion result copied to clipboard.");
7171
await VisualStudioInteraction.ShowMessageBoxAsync(_serviceProvider, "Conversion result copied to clipboard.", conversionResult.GetExceptionsAsString(), false);
7272
}
7373

7474
}
7575

76+
private static async Task SetClipboardTextOnUiThreadAsync(string conversionResultConvertedCode)
77+
{
78+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
79+
Clipboard.SetText(conversionResultConvertedCode);
80+
await TaskScheduler.Default;
81+
}
82+
7683
private async Task WriteConvertedFilesAndShowSummaryAsync(IEnumerable<ConversionResult> convertedFiles)
7784
{
7885
await _outputWindow.WriteToOutputWindowAsync(Intro, true, true);

0 commit comments

Comments
 (0)