I'm trying to refresh the Label on the form every 10s, but it does not matter what I set the $timer.Interval
to, it runs continuously. How can I set the interval?
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()
Running on Win8,
> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1012
Edit
If I run it as a .ps1 it works every time, I can set the interval and it will work for any, but in ISE it works the first time, then if I close the form and run it again with other interval values it does not work. I tried even to remove the variables but somehow it gets set someplace...