Fix possible race that leaks PowerShell object dispose in ForEach-Object -Parallel (#12227)

This commit is contained in:
Paul Higinbotham
2020-04-07 14:31:04 -07:00
committed by GitHub
parent 46071b7ff9
commit 7837a536eb
@@ -867,7 +867,7 @@ namespace System.Management.Automation.PSTasks
}
task.StateChanged -= HandleTaskStateChangedDelegate;
if (!_stopping)
if (!_stopping || stateInfo.State != PSInvocationState.Stopped)
{
// StopAll disposes tasks.
task.Dispose();