1

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?

4

2 回答 2

3

您可以临时设置[Console]::TreatControlCAsInput$true

[Console]::TreatControlCAsInput = $true
Start-Sleep 10  # Ctrl-C will now not abort this sleep.
[Console]::TreatControlCAsInput = $false
于 2020-01-26T16:12:26.113 回答
1

我找到了一种方法来做到这一点:

[System.Threading.Thread]::Sleep(milliseconds)

这会忽略延迟时的 CTRL-C。

于 2020-01-26T16:15:07.040 回答