Powershell 计时器间隔不起作用

Powershell timer interval not working

我试图每 10 秒刷新一次表单上的标签,但是我将 $timer.Interval 设置为什么并不重要,它会连续 运行s。如何设置时间间隔?

function UpdateProcCount()
{
    $Label.Text = (Get-date).ToFileTime()

}

$Form = New-Object System.Windows.Forms.Form
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 10000
$timer.Add_Tick({UpdateProcCount})
$timer.Enabled = $True
$Form.Text = "Sample Form"
$Label = New-Object System.Windows.Forms.Label
$Label.Text = " "
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.ShowDialog()

运行 在 Win8 上,

> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14409  1012    

编辑

如果我 运行 它作为一个 .ps1 它每次都有效,我可以设置间隔并且它适用于任何,但在 ISE 中它第一次有效,那么如果我关闭表单并使用其他间隔值再次 运行 它不起作用。我什至尝试删除变量,但不知何故它被设置在某个地方...

@JohnLBevan 在评论中回答。

相关问题:

在末尾添加 $timer.Dispose() 使其在 ISE 上运行。