I use the latest version of Powershell Studio 2018. I need to understand how to use the job tracker to avoid a not responding error. I read your earlier articles regarding handling loops and forms. Assuming my job is function test, how would I use job tracker to control all aspects of the job. There is no loop in function test and I don't have a progress bar to update. It is just a long slow process that could take many hours and prevent the form from handling events. I would like to see how I make the call from the form for function test.
I assume that even though a new process will be started to call my function, my calling program will wait until the job completes before continuing. This is my understanding of how the job tracker works.
I already loaded the job tracker into my form. Please summaries how I make the call. My function has 3 or more arguments and returns an array and a variable.
thank you for your help,
John Sirabella
Using Job Tracker
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Using Job Tracker
I recommend looking at the "Button - Start Job" control set (ToolBox->Control Sets->Button - Start Job:
The control set provides an example of how to start a job and update the button when the job completes.
As with all jobs, you will have to include the function definition in the Job Script. When job completes, you will have to use Receive-Job cmdlet to get the results of the job. Note: Receive-Job will return whatever is in the pipeline upon completion.
If it will take hours, you might want to prevent the user from closing the form or run the script in a separate process.
The control set provides an example of how to start a job and update the button when the job completes.
As with all jobs, you will have to include the function definition in the Job Script. When job completes, you will have to use Receive-Job cmdlet to get the results of the job. Note: Receive-Job will return whatever is in the pipeline upon completion.
- $results = Receive-Job -Job $Job
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: Using Job Tracker
I want to run this job so i don't get a not responding. However I do not want the script to continue. I would like for the job to complete, get the results and then the script in the form continues on the next line. Am I understanding this correct?
thanks,
John
thanks,
John
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: Using Job Tracker
My apologies for not being clear. I have a button that calls a function. That button calls a 2nd function. The 2nd function is the one that causes the not responding message. I was thinking that in the first function I would create a job that would call the 2nd function. The 1st function would have to wait until the 2nd function completes.
My goal is to avoid a not responding message between these 2 function calls. I am wondering if this is possible? The program works correctly its just because of the long delay I receive the not responding message. The Doevents worked nicely in the loop.
thanks,
John
My goal is to avoid a not responding message between these 2 function calls. I am wondering if this is possible? The program works correctly its just because of the long delay I receive the not responding message. The Doevents worked nicely in the loop.
thanks,
John
Re: Using Job Tracker
Without an example of your code it is not possible to understand how to advise you.
I think once you have experimented with the JobTracker an understand how it works you will be able to see how to use it with your code.
For tasks running more than many minutes without producing output you should consider using a PowerShell scheduled job. Scheduled jobs continue even after the PowerShell session terminates. They can also continue across reboots.
about_Scheduled_Jobs
about_Scheduled_Jobs_Advanced
about_Scheduled_Jobs_Basics
If you need a very long running job then also consider a workflow which also will run across reboots and power failures.
about_Checkpoint-Workflow
about_Suspend-Workflow
about_WorkflowCommonParameters
about_Workflows
I think once you have experimented with the JobTracker an understand how it works you will be able to see how to use it with your code.
For tasks running more than many minutes without producing output you should consider using a PowerShell scheduled job. Scheduled jobs continue even after the PowerShell session terminates. They can also continue across reboots.
about_Scheduled_Jobs
about_Scheduled_Jobs_Advanced
about_Scheduled_Jobs_Basics
If you need a very long running job then also consider a workflow which also will run across reboots and power failures.
about_Checkpoint-Workflow
about_Suspend-Workflow
about_WorkflowCommonParameters
about_Workflows
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: Using Job Tracker
I came up with the following to eliminate the (Not responding) on the top of the form as my form execute a function. It works!!! I'd appreciate your critic of what I created. I did not include the baselineSB scriptblock. The baseline function can take anywhere from minutes to 20 hours depending on the dataset.
$myjob = Start-Job -ScriptBlock { Baseline $args[0] $args[1] $args[2] $args[3] $args[4] } -InitializationScript $baselineSB -ArgumentList $server.server, $sharePath.sharepath, $sharePath.FileMask, $sharePath.recurse, $serverLogBaseline
while (!(Wait-Job $myjob))
{
[System.Windows.Forms.Application]::DoEvents()
}
$completeFileList = Receive-Job $myjob
$fileCount = $completeFileList.length
Get-Job | remove-job
Thank you,
John
$myjob = Start-Job -ScriptBlock { Baseline $args[0] $args[1] $args[2] $args[3] $args[4] } -InitializationScript $baselineSB -ArgumentList $server.server, $sharePath.sharepath, $sharePath.FileMask, $sharePath.recurse, $serverLogBaseline
while (!(Wait-Job $myjob))
{
[System.Windows.Forms.Application]::DoEvents()
}
$completeFileList = Receive-Job $myjob
$fileCount = $completeFileList.length
Get-Job | remove-job
Thank you,
John
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am