Whenever I set a delay in powershell using Start-Sleep
, e.g:
Start-Sleep 10
then it does not ignore CTRLC. I mean when I hit that key stroke the delay quits. How can I ignore it in delays?
Whenever I set a delay in powershell using Start-Sleep
, e.g:
Start-Sleep 10
then it does not ignore CTRLC. I mean when I hit that key stroke the delay quits. How can I ignore it in delays?
您可以临时设置[Console]::TreatControlCAsInput
为$true
:
[Console]::TreatControlCAsInput = $true
Start-Sleep 10 # Ctrl-C will now not abort this sleep.
[Console]::TreatControlCAsInput = $false
我找到了一种方法来做到这一点:
[System.Threading.Thread]::Sleep(milliseconds)
这会忽略延迟时的 CTRL-C。