diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index b769bc026d..326e96dfac 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -604,19 +604,6 @@ namespace System.Management.Automation { _nativeProcess = new Process() { StartInfo = startInfo }; _nativeProcess.Start(); - if (UpstreamIsNativeCommand) - { - SemaphoreSlim processInitialized = _processInitialized; - if (processInitialized is null) - { - lock (_sync) - { - processInitialized = _processInitialized ??= new SemaphoreSlim(0, 1); - } - } - - processInitialized?.Release(); - } } catch (Win32Exception) { @@ -695,6 +682,12 @@ namespace System.Management.Automation } #endif } + + if (UpstreamIsNativeCommand) + { + _processInitialized ??= new SemaphoreSlim(0, 1); + _processInitialized.Release(); + } } if (this.Command.MyInvocation.PipelinePosition < this.Command.MyInvocation.PipelineLength)