Confused on using Start Job/Job Tracker

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
StupidSexyFlanders
Posts: 107
Joined: Sun Nov 27, 2011 9:22 am

Confused on using Start Job/Job Tracker

Post by StupidSexyFlanders »

I am trying to figure out how to use this set of functions to manipulate form controls. I know, from the Sapien blog post on this subject, they cannot be handled directly and that Receive-Job should be used:
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).
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?

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
Mike

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Confused on using Start Job/Job Tracker

Post by davidc »

You should have a fairly good understanding how jobs work before using this technique. I recommend reading the about_jobs and about_job_detail help topics beforehand.


You cannot access variables across jobs. In order to get values you need place objects in the pipeline otherwise nothing will be returned when you call Receive-Job.

The Receive-Job in the update block is there if you want to display information as the job runs, otherwise just call Receive-Job when the job completes.

David
David
SAPIEN Technologies, Inc.

StupidSexyFlanders
Posts: 107
Joined: Sun Nov 27, 2011 9:22 am

Re: Confused on using Start Job/Job Tracker

Post by StupidSexyFlanders »

I use jobs extensively, but it appears I didn't know what I didn't know about background jobs. Thanks, I think this points me in the right direction
Mike

User avatar
Srinath
Posts: 111
Joined: Tue Oct 09, 2012 6:24 am

Re: Confused on using Start Job/Job Tracker

Post by Srinath »

davidc wrote:You should have a fairly good understanding how jobs work before using this technique. I recommend reading the about_jobs and about_job_detail help topics beforehand.


You cannot access variables across jobs. In order to get values you need place objects in the pipeline otherwise nothing will be returned when you call Receive-Job.

The Receive-Job in the update block is there if you want to display information as the job runs, otherwise just call Receive-Job when the job completes.

David
The Job Tracker framework is one of the best snippets came with PS 2012. Even though the Job Tracker blog article is good, it would be nice if it explains on passing arguments.

Actually I was confused at start, but understood after reading your answer to my question in earlier threads.