powershell - 如何在 Powershell 消息框中获取计时器?

标签 powershell timer

我正在尝试在使用 PS Forms 创建的消息框中显示计时器。我想要这样的东西:

1 秒后“您的电脑将在 10 秒后关闭”。

“您的电脑将在 9 秒后关闭”

“您的电脑将在 8 秒后关闭”等等。

希望你能帮助我。

最佳答案

我没有看到刷新消息框中文本的方法。如果我必须这样做,我可能会弹出另一个带有标签的表单,并使用一个计时器在每个刻度上刷新标签的文本。

以下是使用潜在起点的代码示例:

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Form = New-Object system.Windows.Forms.Form
$script:Label = New-Object System.Windows.Forms.Label
$script:Label.AutoSize = $true
$script:Form.Controls.Add($Label)
$Timer = New-Object System.Windows.Forms.Timer
$Timer.Interval = 1000
$script:CountDown = 60
$Timer.add_Tick(
    {
        $script:Label.Text = "Your system will reboot in $CountDown seconds"
        $script:CountDown--
    }
)
$script:Timer.Start()
$script:Form.ShowDialog()

您将需要进行扩展以满足您的需求,例如条件逻辑以在倒计时达到 0 时执行您想要的任何操作(例如重新启动),也许添加一个中止按钮等。

关于powershell - 如何在 Powershell 消息框中获取计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851482/

相关文章:

java - 从 ArrayList<List> 每 X 秒更新一次 JLabel - Java

java - 如何为 drawLine 制作动画?

c# - 使用 Timer 测量 Parallel.ForEach 进度意外暂停

ios - 使用 swift 3 中的计时器自动更改 UIPageViewController 中的页面?

powershell - 我可以让 powershell 选项卡完整显示所有选项,而不是选择一个特定的选项吗?

powershell - 如何在 Powershell Get-Process 中实现 'Wait' 模式

azure - 如何转义 PowerShell 参数中的前导破折号

azure - 使用 Azure 资源管理器模板配置 CORS

powershell - 如何使用 Powershell 2.0 版解压缩 Zip 文件?

java - 自动定时器@Schedule Java EE