However, it is unclear as how go about doing this. There are two Receive-Job variables within the built-in code (both are commented out by default). Do I use one (or both) of those? The instructions above indicate that I should "update the control from the main script"...does that mean I should create my own Receive-Job and leave the others commented out?1. Never access or modify form controls directly from within a job. If you need to update a form control or show progress, use the Receive-Job cmdlet to gather any necessary information from the job first and then update the control from the main script. The form controls do not allow themselves to be accessed from a different thread (i.e., the job).
As a test I created a form with nothing but a Start Job button (along with Job Tracker) and a second but that I can manipulate (e.g. enable/disable). The only change I have made to the default code is to change the default forloop:
PowerShell Code
Double-click the code block to select all.for($i = 0; $i -lt 50; $i++){ Start-Sleep -Milliseconds 100 }...to this one where I count to ten and flip a toggle depending on whether the number is even or odd:
PowerShell Code
Double-click the code block to select all.for($i = 1; $i -lt 10; $i++) { if([bool]!($i%2) -eq $true) { $state = 1 } else { $state = 0 } Start-Sleep 1 }I am assuming I can call the value of $state and use that as a basis for manipulating the other button....I just can't figure out how to do that.
If there is some instruction on this (beyond that quoted paragraph above) please point me in that direction.
Thanks