sleep java示例_如何使用示例的Start-Sleep Command-let教程使PowerShellHibernate?

sleep java示例

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
Sleep Until User Input
Sleep Until User Input
Hibernate直到用户输入

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-nullReadKey()函数的末尾。

开始睡眠作为睡眠命令的别名 (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更简单的别名称为sleepsleep将使用具有相同选项和参数的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
Start-Sleep Interactive Usage
Start-Sleep Interactive Usage
开始睡眠互动用法

在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可以在不同的情况下使用,但是最流行的一种是循环。 ForWhile循环是Start-Sleep好用例。 在此示例中,当计数器可分为5时,我们将睡眠5秒钟。

$val=0


while($val -ne 10)
{
  $val++
  Write-Host $val

  if($val%5 -eq 0)
    {
      Start-Sleep -s 5
    }
}
Sleep In While Loop
Sleep In While Loop
在While循环中睡觉
LEARN MORE  What Is sleep() function and How To Use It In C Program?
了解更多什么是sleep()函数以及如何在C程序中使用它?

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

sleep java示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值