Well i’ve been ill for the past week ![]()
Any luck with this?
I took time to port the above mentioned C# solution to native Powershell. It’s actually almost identical to what is proposed in Microsoft’s Dispatcher.PushFrame Method example.
Function DoEvents()
{
$frame = New-Object System.Windows.Threading.DispatcherFrame
[System.Windows.Threading.DispatcherOperationCallback]$CallBack = { $frame.Continue = $false }
$CurrentDispatcher = [System.Windows.Threading.Dispatcher]::CurrentDispatcher
$CurrentDispatcher.BeginInvoke("Background", $CallBack, $null)
[System.Windows.Threading.Dispatcher]::PushFrame($frame)
}
The forum’s engine doesn’t take XAML, so here’s a pastebin working example: http://pastebin.com/0zgaVqKJ
The button initiates a count to 5. Strangely, WPF updates the windows title but fails to update any child control. If you uncomment #DoEvent call it fixes it.
Actually, there’s a quicker fix. Instead you can use a one-liner calling this windows’ dispatches with an empty action:
$Window.Dispatcher.Invoke("Background", [action]{})
To be honest I don’t fully understand the coding esoterics behind it, the C# equivalents of these techniques are discussed here and the comments are ambiguous, some claim one solution is safer the others say the opposite. Go figure. But in my tests they both work and they both quirk. Sometimes they lag and fail to flush the event buffer in time.
I took time to port the above mentioned C# solution to native Powershell. It’s actually almost identical to what is proposed in Microsoft’s Dispatcher.PushFrame Method example.
Function DoEvents()
{
$frame = New-Object System.Windows.Threading.DispatcherFrame
[System.Windows.Threading.DispatcherOperationCallback]$CallBack = { $frame.Continue = $false }
$CurrentDispatcher = [System.Windows.Threading.Dispatcher]::CurrentDispatcher
$CurrentDispatcher.BeginInvoke("Background", $CallBack, $null)
[System.Windows.Threading.Dispatcher]::PushFrame($frame)
}
The forum’s engine doesn’t take XAML, so here’s a pastebin working example: http://pastebin.com/0zgaVqKJ
The button initiates a count to 5. Strangely, WPF updates the windows title but fails to update any child control. If you uncomment #DoEvent call it fixes it.
Actually, there’s a quicker fix. Instead you can use this one-liner calling the windows’ dispatches with an empty action:
$Window.Dispatcher.Invoke("Background", [action]{})
To be honest I don’t fully understand the coding esoterics behind it, the C# equivalents of these techniques are discussed here and the comments are ambiguous, some claim one solution is safer the others say the opposite. Go figure. But in my tests they both work and they both quirk. Sometimes they lag and fail to flush the event buffer in time.