Jobtracker - startjob working, want to update progressbar as coms are processed

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Jobtracker - startjob working, want to update progressbar as coms are processed

Post by angelofstealth »

Is there a way to return the $i (int) value to the UpdateScript to update a progressbar while the job is in progress. I have tried creating an object and calling that object in the return results in UpdateScript and passing back the value of $i from JobScript. Since I am already returning objects back once the Total has completed is that causing the issue? Or would you recommend another way to get the value of $i to UpdateScript. Appreciate the help, thanks
Attachments
Job Progress bar - test.ps1
(7.96 KiB) Downloaded 114 times
Last edited by angelofstealth on Wed Feb 06, 2019 9:34 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by jvierra »

Please note that forum rules request that scripts more than a dozen lines be attached as a file. Please attach your script as a file by editing your original post.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by jvierra »

You can use Write-Progress inside the job.

Retrieve the progress form th job in the update script.


$job.ChildJobs[0].Progress
$job.ChildJobs[0].Progress.Clear()
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by angelofstealth »

What I am trying to do is every time objects are returned from a computer, update global variables with the values. When the total computers values are returned, update the datagridview and a progressbar as values are returned. I have tried using a job for each computer object and in the completedscript I don't update the datagridview until all objects are pulled back. What I find with this method is the progressbar is flashy and it never completes the last bit of the image/progressstep until the completedscript is done. Even though i will tell it to progressstep or the value is 100, refresh the progressbar and form with no change. So are the progressbars really only good for updating on starting jobs instead of completed jobs. Based on design is it best to use one job and invoke a bunch of computers or multiple jobs per computer. As I am pulling back a lot of data at once. I have attached a ps1 file with the button click which works and pulls the data back and updates the progressbar, but does not fully complete the progressstep, it will update the text correctly. The weird thing is if I put a message box after (if ($tab1_progressbaroverlay1.value -eq $tab1_progressbaroverlay1.Maximum)), ie a pause the progressbar will be completed. Like it is a screen refresh issue. Always appreciate the feedback and support jvierra.
Attachments
Job Progress bar - Progress Updated in Completed.ps1
(9.49 KiB) Downloaded 117 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by jvierra »

You have to update the grid and ProgressBar in the UpdateScript and not in the CompletedScript.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by jvierra »

You also should be using a workflow for this as it will return all results in parallel. You really don't need a ProgressBar as the grid will update in real time.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by angelofstealth »

I can't update grid in the updatescript area as the objects i am sending back through Jobscript are not returning any data.
If I use the following code in CompletedScript i get the object data, in UpdateScript i return null. Thought you could not pass variables to the UpdateScript, only information about the job itself. I know I could cheat with a step by making the Datagridview updates at the end part of the overall total max of the progressbar it will update without no issues. I think I might scrap the progressbar, was only using it as a way of relaying to the user it was completed pulling data back. Could use other ways to do this.

Example Code:

Code: Select all

Param ($Job)
$Results = Receive-Job -Job $Job
$Results.'InvokeResults_ComputerCPUInfo'
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Jobtracker - startjob working, want to update progressbar as coms are processed

Post by jvierra »

That is why I suggested a workflow. It will be faster and these issues will go away. Workflows do the remoting management for you.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked