Page 1 of 3

Help with the responsive form

Posted: Wed Sep 20, 2017 12:31 pm
by gutihz
Hi Everyone,
Need some help/understanding of the blog I read on this site here https://www.sapien.com/blog/2012/05/16/ ... ive-forms/

Now according to this blog, using the "Add-JobTracker" I can add a job. When I add my scriptblock, it works like a charm. However, I don't understand how I can add a foreach block that has 20 scriptblocks and pass that to the add-Jobtracker part and also update the progressbar with this.

I thought of calling the Add-jobtracker one by one but that would not only defeat the purpose of this blog but that would complicate the progressbar.

Anyone can explain how to accomplish this? Am I on the wrong path or didn't get the blog at all?
I added a modified downloaded project to what I'm asking and attached here.

Thanks in advance.

--------------------------------------
PowerShell Studio 2016 5.2.124
Version of product: 64
Operating system: Windows 7
OS: 64 bit

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 12:50 pm
by jvierra
Why would you add 20 scripts to the same job? That makes no sense. Are you saying you want to create 20 separate jobs? Just add the jobs one at a time. JobTracker will manage multiple jobs.
If you have 20 steps and you want them to run parallel as one job then use a workflow and add that as a job.

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 3:28 pm
by gutihz
I have about 20 scripts that copies different things. Some are files as little as 10kb but some are as big as 10gb. What I'm trying to do is run everything at once without freezing the GUI but update the progress bar step as the small files complete.

I've been looking around, saw lots of examples but couldn't actually find one that explains what I'm trying to do.
Any ideas?

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 3:48 pm
by jvierra
Just add 20 jobs to the JobTracker. They will all run in parallel.

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 4:04 pm
by gutihz
Hi jvierra,

Can you give me an example on how to add multiple jobs? I'm looking at the functions and don't see how that can be accomplished.

in a very simple example I tried doing :
foreach($i in $alljobs)
{
Add-jobtracker -scriptblock {$i}
}
which didn't work.

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 4:13 pm
by jvierra
Just run Add-JobTracker multiple times. That is why it is called "Add"-JobTracker. The verb in PS always telss us what a CmdLet is trying to do.

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 4:23 pm
by gutihz
I get that. Thanks!
but that didn't update progressbar correctly. after the first script, it just completes as 100% as I mentioned in my initial post.

Re: Help with the responsive form

Posted: Wed Sep 20, 2017 4:28 pm
by jvierra
You will need to be sure the Update script runs for all jobs and that the progress steps are set correctly as well as the initial value. This will require using arithmetic and some serious design thinking to adapt the tracker to your requirements.

Re: Help with the responsive form

Posted: Fri Sep 22, 2017 4:07 pm
by gutihz
So here is what I got so far...

I have a listview. So the folder gets copied over, but I can't update the subitem to either "Success" or "Error".

Any ideas what could be causing this issue?

Thanks in advance!

Code: Select all

$Test = $listview.Items.Add("Copying Folder")
				if (Test-Path "C:\Temp\From")
				{
					
					$Test.Subitems.Add("Folder exists")
					$Test.Subitems.Add("Copying...")
					Add-JobTracker -Name "Test" `
								   -JobScript $sb -ArgumentList "C:\Temp\From", 'C:\test' `
								   -CompletedScript {
						Param ($job)
						$Compare = CompareFolderSize "C:\Temp\From" 'C:\test'
							if ($Compare -eq $true)
							{
								$Test.Subitems[2].Text = "Success"
							}
							else
							{
								$Test.Subitems[2].Text = "Error"
							}
						
					}` -UpdateScript {
						Param ($job)
						while (Get-job -State "Running" | Where-Object{ $_.Name.Contains("Test") })
						{
							$Test.Subitems[2].Text = "Still Copying"
						}
	
					}
				}
				else
				{
					$copyError = "ERROR - Check folder or file"
					$Test.Subitems.Add($copyError)
				}

Re: Help with the responsive form

Posted: Fri Sep 22, 2017 4:32 pm
by jvierra
For this it would be easier to use a DataGridView,

In the update script you need to get a copy of the list item. The one you have is out of scope when the timer tick runs the "Update" block.

This should work although I would use a better name:

$global:Test =$listview.Items.Add("Copying Folder")

I would use:

$global:g_CurrentItem=$listview.Items.Add("Copying Folder")