for ($i = 0; $i -lt $datagridview_main.RowCount; $i++)
{
if ($datagridview_main.Rows[$i].Cells[6].Value -eq $true)
{
# $source and $destination variables are filled correctly
Add-JobTracker -Name "JobCopy$i" -ArgumentList $source, $destination, $i `
-JobScript { Param ($source,$destination)
robocopy $source $destination /MIR /E /ETA /NC /NP /R:10 /W:10 /TEE /LOG:"$env:ProgramData\ViSiT\LogFiles\logfile_$(get-date -f MM-dd-yyyy_HH_mm).log"
}`
-UpdateScript { Param ($Job)
# fill the Statusbar Label
}`
-CompletedScript {
Param ($Job, $i)
# doing all other stuff after finishing the job
Update-XMLDGV $i
<#
$root = $global:EntriesXML.DocumentElement
$node = $root.SelectSingleNode("//Entry[@Number=$($i + 1)]/version_lokal")
$node.InnerText = $datagridview_main.Rows[$i].Cells[4].Value
$node = $root.SelectSingleNode("//Entry[@Number=$($i + 1)]/datum_lokal")
$node.InnerText = $datagridview_main.Rows[$i].Cells[5].Value
$node = $root.SelectSingleNode("//Entry[@Number=$($i + 1)]/pfad_lokal")
$node.InnerText = $destination
$global:EntriesXML.Save($global:xmlEntriesFile)
$datagridview_main.Rows[$i].Cells[2].Value = $datagridview_main.Rows[$i].Cells[4].Value
$datagridview_main.Rows[$i].Cells[3].Value = $datagridview_main.Rows[$i].Cells[5].Value
#>
}
}
}
A question of Scope?
The result of the Downloadbutton is that for every row where the checkbox is checked an Add-JobTracker will be created.
I had a lot code outside the tracker. I put it in the tracker, here commented out, because I embedded the comments in an extra function Update-XMLDGV for debugging purpose. I can't step in the Debugging Mode throw the Job and the -CompletedScript Part. If I put this code in the extra function the Debugger jumps to the function and I can step throw and see the values.
The result is the same.
If the loop runs row by row $i is 0,1,2,3,4,5, .... , DGV rowcount.
If I create a Jobtracker and with $i in the argumentlist, doesn't it means that $i get the value 0,1,2,3,4,5, .... , DGV rowcount in the scope of the Job?
If the Job is finished the Code will be execute in the function Update-XMLDGV or if I has the block directly under -CompletedScript, but the $i is empty and all what needs the index will fail.
I'm stand a little bit on the tube. ;(