diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 3d31ede06..325e7220f 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -228,8 +228,10 @@ protected override void EndProcessing() using EditorServicesLoader psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers); _logger.Log(PsesLogLevel.Verbose, "Loading EditorServices"); - // Start editor services and wait here until it shuts down + // Synchronously start editor services and wait here until it shuts down. +#pragma warning disable VSTHRD002 psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult(); +#pragma warning restore VSTHRD002 } catch (Exception e) { diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index 97ee2edd7..cca3ad156 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -769,7 +769,14 @@ private void RunExecutionLoop(bool isForDebug = false) && !cancellationScope.CancellationToken.IsCancellationRequested && _taskQueue.TryTake(out ISynchronousTask task)) { - task.ExecuteSynchronously(cancellationScope.CancellationToken); + try + { + task.ExecuteSynchronously(cancellationScope.CancellationToken); + } + catch (OperationCanceledException e) + { + _logger.LogDebug(e, "Task {Task} was canceled!", task); + } } if (_shouldExit diff --git a/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs b/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs index 2ae739c26..b2e5e6b46 100644 --- a/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs +++ b/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs @@ -33,7 +33,9 @@ public ExtensionCommandTests() serviceProvider: null, editorOperations: null, executionService: psesHost); +#pragma warning disable VSTHRD002 extensionService.InitializeAsync().Wait(); +#pragma warning restore VSTHRD002 extensionCommandService = new(extensionService); } @@ -110,7 +112,8 @@ await psesHost.ExecutePSCommandAsync( Assert.Equal(commandName, commandAdded.Name); Assert.Equal(commandDisplayName, commandAdded.DisplayName); - // Invoke the command + // Invoke the command. + // TODO: What task was this cancelling? await extensionCommandService.InvokeCommandAsync("test.scriptblock", editorContext).ConfigureAwait(true); // Assert the expected value