I'm new on WPF/PowerShell and I'm trying to execute a locally defined Powershell function inside a DispatcherTimer Tick scriptblock but I get this error
My code is simply :
function Get-CurrentStorageJobs
{
My_Code
}
$MonitorTimer = New-Object System.Windows.Threading.DispatcherTimer
$MonitorTimer.Interval = New-TimeSpan -Seconds 3
$MonitorTimer.Add_Tick({ Get-CurrentStorageJobs })
$MonitorTimer.Start()
I assumed the function didn't exist in the Tick scriptblock context so I tried to pass the function in the same way as I do with Invoke-Command scriptblock:
$MonitorTimer.Add_Tick(${ function:Get-CurrentStorageJobs })
But it failed also...
Could somebody help me ?