Reputation: 115
I want to have a Progressbar in my Powershell application, which progress is changed during executing the functions. Once one function is ended, I want to move Progressbar a little.
Progressbar is declared in XAML:
<ProgressBar x:Name="ProgressBar"
HorizontalAlignment="Left"
Height="20"
Margin="0,672,0,0"
VerticalAlignment="Top"
Width="754" Grid.ColumnSpan="4"/>
Then, I'm trying to change the Progressbar value during event Button_Click:
$ProgressBar.Value = 0
Function1
$ProgressBar.Value = 30
Function2
$ProgressBar.Value = 100
I tried this logic using Write-Progress and it works, also tried with non-xaml .Net Powershel implemented in Powershell - with success. Do I need to use Background Jobs? Or maybe there's another solutions.
Do you have any ideas?
Upvotes: 0
Views: 4015
Reputation: 857
Sorry to resurrect an old thread, but this is something that I have been working a lot on lately. Not exactly sure if this is the case because of the lack of code, but you could try this if your ProgressBar is on a different thread. It will wait for the dispatcher to have an opening and update the ProgressBar on the UI thread
$ProgressBar.Dispatcher.Invoke([action]{
$ProgressBar.Value = 30
}, "Normal")
Edit: Another way to accomplish this task would be using a dispatcherTimer, where you could tell it how often you want the component updated. This was a resource that helped me understand the basic concept of the DispatcherTimer https://richardspowershellblog.wordpress.com/2011/07/07/a-powershell-clock/
Upvotes: 1