From 651fa4648263a394b0d74b58932c99df71427c42 Mon Sep 17 00:00:00 2001 From: Ruben Guerrero Samaniego Date: Wed, 6 Mar 2024 16:18:23 -0800 Subject: [PATCH] Fix PowerShellCmdlet --- src/PowerShell/CommonFiles/PowerShellCmdlet.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/PowerShell/CommonFiles/PowerShellCmdlet.cs b/src/PowerShell/CommonFiles/PowerShellCmdlet.cs index 03d4ea188e..bd66db5ef7 100644 --- a/src/PowerShell/CommonFiles/PowerShellCmdlet.cs +++ b/src/PowerShell/CommonFiles/PowerShellCmdlet.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -281,6 +281,7 @@ internal void Wait(Task runningTask, PowerShellCmdlet? writeCmdlet = null) { try { + this.pwshThreadEdi = null; this.pwshThreadAction(); } catch (Exception e) @@ -596,12 +597,17 @@ private void WaitMainThreadActionCompletion() this.pwshThreadActionCompleted.WaitHandle, }); - if (this.pwshThreadEdi != null) + try { - this.pwshThreadEdi.Throw(); + if (this.pwshThreadEdi != null) + { + this.pwshThreadEdi.Throw(); + } + } + finally + { + this.semaphore.Release(); } - - this.semaphore.Release(); } private class QueuedStream