ShowUI background jobs (error?)

Oct 27, 2011 at 1:26 PM

Hi guys!

James maybe you can help me (at least Jaykul said that). I am trying to use the latest stable ShowUI (version 1.3), and have played around with the examples. I need to run background jobs, and display the actual status (eg.: with a progressbar) to the user.
But the code below dosen't work as expected. If I run it, the value of "$i" reaches 10 or 11 and then the loop stops. According to this, the progress bar shows the value of 10 or 11.
If i decrease the value of "$sleep", the loop goes further and "$i" reaches higher value (and the progressbar too). Why is this? And why stops the loop, and dosen't reaches "All Done"?

Import-Module ShowUI

New-StackPanel -Width 200 {
   New-TextBlock -Margin 10 -TextWrapping Wrap -FontWeight Bold -FontSize 12 -DataBinding @{"Text" = "LastProgress.Activity"}
   New-TextBlock -Margin 10 -TextWrapping Wrap -FontStyle Italic -FontSize 12 -DataBinding @{"Text" = "LastProgress.StatusDescription"}
   New-ProgressBar -Margin 10 -MinHeight 25 -DataBinding @{"Value" = "LastProgress.PercentComplete"}
} -On_Loaded {
   Invoke-Background -control $this -ScriptBlock {
       $sleep = 25
       for ($i=0; $i -lt 100; $i++) {
           Write-Progress "MajorProgress $i" "MinorProgress $sleep" -PercentComplete $i
           Start-Sleep -Milliseconds $sleep
       Write-Progress "All" "Done" -Completed
} -Show


Regards Peter

Nov 7, 2011 at 7:43 AM

Could someone answer this?


Nov 17, 2011 at 6:38 PM

I'm really sorry this has gone so long. I'll try to look into it myself this evening (that, or make sure James does)

Jun 7, 2013 at 7:34 AM
It's too late to help now, but I owed you this post, and maybe it will help someone else ... the bottom line is that although you probably need to handle the events from InvokeBackground. The databinding as in the example should work, but I have been playing with it for 2 hours and I am not able to get it to work ;-)