diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 9cbc1dcbb..018a70224 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -36,7 +36,7 @@ namespace Microsoft.PowerShell.EditorServices.Commands public sealed class StartEditorServicesCommand : PSCmdlet { // TODO: Remove this when we drop support for PS6. - private static bool s_isWindows = + private readonly static bool s_isWindows = #if CoreCLR RuntimeInformation.IsOSPlatform(OSPlatform.Windows); #else diff --git a/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs b/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs index 5689bb8b6..af524352c 100644 --- a/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs +++ b/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs @@ -286,7 +286,10 @@ public StreamLogger(StreamWriter streamWriter) _messageQueue = new BlockingCollection(); // Start writer listening to queue - _writerThread = new Thread(RunWriter); + _writerThread = new Thread(RunWriter) + { + Name = "PSES Stream Logger Thread", + }; _writerThread.Start(); } @@ -306,6 +309,8 @@ public void OnCompleted() _fileWriter.Flush(); _fileWriter.Close(); _fileWriter.Dispose(); + _cancellationSource.Dispose(); + _messageQueue.Dispose(); } public void OnError(Exception error) diff --git a/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs b/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs index c6edb2591..b842193c7 100644 --- a/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs +++ b/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs @@ -326,7 +326,7 @@ private Task InvokePowerShellAsync(PSCommand command) private PowerShellResult InvokePowerShell(PSCommand command) { - using (var powerShell = System.Management.Automation.PowerShell.Create()) + using (var powerShell = System.Management.Automation.PowerShell.Create(RunspaceMode.NewRunspace)) { powerShell.RunspacePool = _analysisRunspacePool; powerShell.Commands = command; @@ -441,7 +441,7 @@ private IEnumerable GetPSScriptAnalyzerRules() /// A runspace pool with PSScriptAnalyzer loaded for running script analysis tasks. private static RunspacePool CreatePssaRunspacePool(out PSModuleInfo pssaModuleInfo) { - using (var ps = System.Management.Automation.PowerShell.Create()) + using (var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.NewRunspace)) { // Run `Get-Module -ListAvailable -Name "PSScriptAnalyzer"` ps.AddCommand("Get-Module")