← All Scenarios
· Scenario 03
Dispose() While Running
Goal
Verify Dispose() doesn't hang indefinitely when a pipeline is active. Before the fix, Dispose → Close → StopPipelines → sequential Stop → WaitOne(∞) would hang forever.
Trying to break
After the fix, StopPipelines has a 30s aggregate timeout and Dispose catches TimeoutException — ensuring Dispose always terminates.
2 test stepsPress Start to walk through the scenario step by step.
View full script source (dispose-while-running.ps1)
$job = Start-Job {
Add-Type -AssemblyName System.Management.Automation
$rs = [RunspaceFactory]::CreateRunspace()
$rs.Open()
$ps = [PowerShell]::Create()
$ps.Runspace = $rs
$ps.AddScript('Start-Sleep -Seconds 300') > $null
$null = $ps.BeginInvoke()
Start-Sleep -Milliseconds 300
$ps.Dispose() # <-- previously hung here
$rs.Dispose()
'completed'
}
$job | Wait-Job -Timeout 90