#PowerShell 的 Start-Sleep 命令
Start-Sleep [-Seconds] <Double>
Start-Sleep -Milliseconds <Int32>
Start-Sleep -Duration <TimeSpan>
功能
暂停当前脚本或会话一段时间,随后继续执行。可以用 Ctrl+C 中断等待。
类型
Cmdlet,属于 Microsoft.PowerShell.Utility。
参数
-Seconds以秒为单位,支持小数。-Milliseconds以毫秒为单位。-Duration接收TimeSpan,从 PowerShell 7.3 起可用。
#示例
在两次输出之间暂停
Write-Output '开始'
Start-Sleep -Milliseconds 300
Write-Output '完成'
开始
完成
第二行在约 300 毫秒后显示。