Prerequisites
Steps to reproduce
try
{
echo Sleeping...
Start-Sleep 5
echo Exiting...
}
finally {
echo Finally...
echo "Exit code: $LASTEXITCODE"
}
Running it: conhost cmd /k pwsh -f test.ps1, then hitting Ctrl+C after Sleeping... shows up, I only see Finally... about 1 out 10 runs.
Expected behavior
The following output should be consistently displayed:
Finally...
Exit code: 0
### Actual behavior
```console
In most cases (but not always), `finally` block doesn't get executed when Ctrl+C is pressed in the middle of `Start-Sleep` execution.
Error details
Environment data
❯ $PSVersionTable
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
### Visuals
_No response_
Prerequisites
Steps to reproduce
Running it:
conhost cmd /k pwsh -f test.ps1, then hitting Ctrl+C afterSleeping...shows up, I only seeFinally...about 1 out 10 runs.Expected behavior
Error details
N/AEnvironment data