Progressbar problem still exist

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 8 years and 2 weeks 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
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar problem still exist

Post by dan.potter »

I use a combination of progressbar and statusbar on one of my forms.

set the progressbar maximum to your selected rows count. In the updatescript write something to the statusbar. In the completed script progressbar.performstep()
  1. $statusbarpanel1.Text = 'Loading jobs...'
  2.  
  3. $progressbar1.Maximum = $datagridview1.SelectedRows.Count
  4. $progressbar1.Step = 1
  5. $progressbar1.Value = 0
  6.  
  7.  
  8. foreach ($row in $datagridview1.SelectedRows) {
  9.    
  10.     $server = $row.Cells[0].Value
  11.    
  12.     if (test-connection $server -count 1 -erroraction "silentlycontinue") {
  13.        
  14.        
  15.         $JobScript = {
  16.            
  17.             param ($server,
  18.                 $credential)
  19.             'get a ton of server info'
  20.            
  21.         }
  22.        
  23.         $UpdateScript = {
  24.             Param ($Job)
  25.             $statusbarpanel1.Text = 'Working...'
  26.         }
  27.        
  28.         $CompletedScript = {
  29.            
  30.             Param ($Job)
  31.             $results = Receive-Job -Job $Job
  32.             'populate datagrid with results'
  33.             $statusbarpanel1.Text = $results.server + " Complete."
  34.             $progressbar1.PerformStep()
  35.            
  36.         }
  37.        
  38.         Add-JobTracker -Name $server -JobScript $JobScript -UpdateScript $UpdateScript -CompletedScript $CompletedScript -ArgumentList $server, $credential
  39.     }
  40. }
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Progressbar problem still exist

Post by monoeagle »

Hi Dan,

thanks for snippet.

greetz
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Progressbar problem still exist

Post by monoeagle »

  1. for ($i = 0; $i -lt $datagridview_main.RowCount; $i++)
  2. {
  3. if ($datagridview_main.Rows[$i].Cells[6].Value -eq $true)
  4. {
  5.  
  6. # $source and $destination variables are filled correctly
  7.  
  8. Add-JobTracker -Name "JobCopy$i" -ArgumentList $source, $destination, $i `
  9.  -JobScript { Param ($source,$destination)
  10.     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"
  11. }`
  12.  -UpdateScript { Param ($Job)
  13.    # fill the Statusbar Label
  14. }`
  15.  -CompletedScript {
  16.  Param ($Job, $i)
  17.  
  18. # doing all other stuff after finishing the job
  19.  
  20.     Update-XMLDGV $i
  21.                
  22. <#
  23. $root = $global:EntriesXML.DocumentElement
  24. $node = $root.SelectSingleNode("//Entry[@Number=$($i + 1)]/version_lokal")
  25. $node.InnerText = $datagridview_main.Rows[$i].Cells[4].Value
  26. $node = $root.SelectSingleNode("//Entry[@Number=$($i + 1)]/datum_lokal")
  27. $node.InnerText = $datagridview_main.Rows[$i].Cells[5].Value
  28. $node = $root.SelectSingleNode("//Entry[@Number=$($i + 1)]/pfad_lokal")
  29. $node.InnerText = $destination
  30. $global:EntriesXML.Save($global:xmlEntriesFile)
  31.  
  32. $datagridview_main.Rows[$i].Cells[2].Value = $datagridview_main.Rows[$i].Cells[4].Value
  33. $datagridview_main.Rows[$i].Cells[3].Value = $datagridview_main.Rows[$i].Cells[5].Value
  34. #>
  35. }
  36. }
  37. }
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. ;(
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar problem still exist

Post by dan.potter »

There must be a foreach in there somewhere.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Progressbar problem still exist

Post by monoeagle »

no foreach

if I use a global variable and set this to zero. The Variable will be empty. :?: *click* the variable was 0, but if loop(for ($i = 0; $i -lt $datagridview_main.RowCount; $i++)) was running $i will be empty and then the global variable too.
Bildschirmfoto 2016-03-30 um 15.10.25.png
Bildschirmfoto 2016-03-30 um 15.10.25.png (13.17 KiB) Viewed 3559 times
Bildschirmfoto 2016-03-30 um 15.28.04.png
Bildschirmfoto 2016-03-30 um 15.28.04.png (64.71 KiB) Viewed 3552 times
Bildschirmfoto 2016-03-30 um 15.16.32.png
Bildschirmfoto 2016-03-30 um 15.16.32.png (39.27 KiB) Viewed 3559 times
It's confusing extremly.

Maybe time for quitting time.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar problem still exist

Post by dan.potter »

I don't understand what your are trying to do.
  1. $form1_Load = {
  2.    
  3.     (1..4) | %{$datagridview1.Rows.Add($null,'row'+$_) }
  4.    
  5. }
  6.  
  7.  
  8. $button1_Click={
  9.    
  10.     $checkedrows = $datagridview1.Rows | ? { $_.Cells[0].Value -eq 'Checked' }
  11.    
  12.     foreach ($row in $checkedrows) { Write-Host "addjobtracker for" $row.cells[1].value}
  13.        
  14.     }
Last edited by dan.potter on Wed Mar 30, 2016 7:06 am, edited 1 time in total.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Progressbar problem still exist

Post by monoeagle »

hmm maybe I think to complicated.

I have a datagridview and for every checked row a job will be generated if the download button was pressed.
If a job is finished an XML will be edited the 2 cells in the datagridview. This 2 actions have to be in the -CompletedScript Part??
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar problem still exist

Post by dan.potter »

I think you're taking on too much at once. Start small with the code above. Add the job tracker function and practice editing the rows with the results of the jobs.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Progressbar problem still exist

Post by monoeagle »

thanks for your help/hint, now it's time for a coffee and round 2. =)

hmmmm with the foreach I can handle all for a checked row but I lose the index of the row which I need so select the entry in the XML.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar problem still exist

Post by dan.potter »

dgvtesting.psf
(35.17 KiB) Downloaded 193 times
This topic is 8 years and 2 weeks 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