
sleep java示例
PowerShell is not just a shell where it can provide programmatic features. We can use Start-Sleep
command-let in order to suspend the script or activity for specified period of time.
PowerShell不仅仅是可以提供编程功能的外壳。 我们可以使用Start-Sleep
Command-let来在指定的时间段内暂停脚本或活动。
句法 (Syntax)
Start-Sleep
has very simple syntax where we will just provide the options which is used to specify seconds or milliseconds and the time we want to sleep.
Start-Sleep
具有非常简单的语法,其中我们仅提供用于指定秒数或毫秒数以及我们要Hibernate的时间的选项。
Start-Sleep OPTION TIME
每秒睡眠 (Sleep As Seconds)
We will start with the sleeping or suspending in seconds. We will use -s
option with the time which is 5
seconds in this example.
我们将从几秒钟的睡眠或暂停开始。 在此示例中,我们将使用-s
选项,时间为5
秒。
PS> Start-Sleep -s 5
睡眠10秒 (Sleep For 10 Seconds)
In this example we will sleep the PowerShell for 10
seconds.
在此示例中,我们将使PowerShellHibernate10
秒钟。
PS> Start-Sleep -s 10
睡眠60秒 (Sleep For 60 Seconds)
In this example we will sleep the PowerShell for 60
seconds.
在此示例中,我们将使PowerShellHibernate60
秒。
PS> Start-Sleep -s 60
睡眠数毫秒 (Sleep For Milliseconds)
In some cases we may need more precises values to sleep or suspend the execution. We can use milliseconds
as time value. We will use -m
in order to change time to the milliseconds. In this example we will sleep for 50
milliseconds.
在某些情况下,我们可能需要更精确的值来Hibernate或暂停执行。 我们可以使用milliseconds
作为时间值。 我们将使用-m
来将时间更改为毫秒。 在此示例中,我们将Hibernate50
毫秒。
PS> Start-Sleep -m 50
Hibernate直到用户输入 (Sleep Until User Input)
We have all ready learned the usage of Start-Sleep
to suspend specified time. We can also use ReadKey
function in order to suspend execution of the script or shell up to a user input. The user input is just a keystroke which will start the execution again.
我们已经准备好学习使用Start-Sleep
来暂停指定的时间。 我们还可以使用ReadKey
函数来中止脚本或shell的执行,直到用户输入为止。 用户输入只是一个按键,它将再次开始执行。
PS> $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null

If we do not want to print input to the console we can add | out-null
to the end of the ReadKey()
function.
如果我们不想将输入输出到控制台,则可以添加| out-null
| out-null
到ReadKey()
函数的末尾。
开始睡眠作为睡眠命令的别名 (Start-Sleep As Alias of sleep Command)
Start-Sleep
name refers to the PowerShell explicitly. We can use more simple alias of Start-Sleep
named sleep
. sleep
will use Start-Sleep
with the same options and argument. In this example we will sleep for 3
seconds with -s
option.
Start-Sleep
名称明确引用了PowerShell。 我们可以使用Start-Sleep
更简单的别名称为sleep
。 sleep
将使用具有相同选项和参数的Start-Sleep
。 在此示例中,我们将使用-s
选项睡眠3
秒钟。
PS> sleep -s 3
开始睡眠互动用法 (Start-Sleep Interactive Usage)
We can also use Star-Sleep
command-let in a interactive way in PowerShell. We will just call the Start-Sleep
like below and then input the parameter.
我们还可以在PowerShell中以交互方式使用Star-Sleep
Command-let。 我们将像下面这样调用Start-Sleep
,然后输入参数。
PS> Start-Sleep

在While循环中睡觉(Sleep In While Loop)
Start-Sleep
can be used in different cases but one of the most popular one will be a loop. For
and While
loops are good use cases for Start-Sleep
. In this example we will sleep for 5 seconds when the counter can be divided into 5.
Start-Sleep
可以在不同的情况下使用,但是最流行的一种是循环。 For
和While
循环是Start-Sleep
好用例。 在此示例中,当计数器可分为5时,我们将睡眠5秒钟。
$val=0
while($val -ne 10)
{
$val++
Write-Host $val
if($val%5 -eq 0)
{
Start-Sleep -s 5
}
}

翻译自: https://www.poftut.com/how-to-sleep-powershell-with-start-sleep-command-let-tutorial-with-examples/
sleep java示例