After the last Editor Session was killed with an mysql error I have to type all again.
Powershell Studio: 2014 --> working
Powershell Studio: 2015(4.2.95) --> not working
System: Win7 x64
Used PS Version: v2 or v4 x64, on both the progressbar doesn't run on the Powershell Studio 2015
Problem:
On the 2014 Powershell Studio my Progressbar was working.
After fresh install ob 2015 Powershell Studio the Progressbar is not working.
Application:
I have a DataGridView with some Columns with Buttons. If the Button was pressed the Progressbar should show the % Action.
Part where my Datagrid reacts:
Code: Select all
$datagridview1_CellContentClick=[System.Windows.Forms.DataGridViewCellEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
#....
if ($_.ColumnIndex -eq 5)
{
$timer.Start()
$pgb_robocopy.Value = 0
$global:currentcnt = 0
# get file count
$global:totalcnt = (Robocopy "C:\Quelle" "C:\Ziel" /MIR /S /ETA /L /NC /NP).length - 1
$i = 0
# create job
$global:job = Start-Job -ScriptBlock {
robocopy "C:\Quelle" "C:\Ziel" /MIR /S /ETA /NC /NP /R:10 /W:10 /TEE /LOG:"C:\temp\logfile_$(get-date -f MM-dd-yyyy).log"
}
#...
}
#.....
}
#
$handler_tick = {
$global:currentcnt += ($global:job | Receive-Job).Count
$percent = ($global:currentcnt / $global:totalcnt) * 100
if ($percent -lt 100)
{
$pgb_robocopy.Value = $percent
}
else
{
$pgb_robocopy.Value = 100
$timer.Enabled = $false
$global:job | remove-job -ErrorAction SilentlyContinue
}
}
Definition Variables in Global.ps1
Code: Select all
$global:job = $null
$global:currentcnt = 0
$global:totalcnt = 0
Startup.ps1
Code: Select all
function Main {
Param ([String]$Commandline)
#Timer settings
$timer.add_tick($handler_tick)
$timer.Enabled = $false
$timer.Interval = 500
if((Call-MainForm_psf) -eq "OK")
{
}
$timer.dispose()
}
If I use this Example standalone it works with both Powershell Studio Version:
Code: Select all
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button1 = New-Object System.Windows.Forms.Button
$progress = New-Object System.Windows.Forms.ProgressBar
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$timer = New-Object System.Windows.Forms.Timer
#endregion Generated Form Objects
$global:job = $null
$global:currentcnt = 0
$global:totalcnt = 0
$handler_button1_Click= {
if ($button1.Text -eq "Start"){
$timer.Start()
$button1.Text = "Running"
$button1.Enabled = $false
$progress.Value = 0
$global:currentcnt = 0
# Anzahl der Dateien ermitteln
$global:totalcnt = (robocopy "C:\quelle" "C:\ziel" /S /ZB /ETA /L /NS /NC /NJH /NJS /NDL ).length -1
$i = 0
$global:job = Start-Job -ScriptBlock {
robocopy "C:\quelle" "C:\ziel" /S /ZB /ETA /NS /NC /NJH /NJS /NDL /NP /R:10 /W:10
}
}else{
$timer.Stop()
$global:job | stop-job
$global:job | remove-job -Force
$button1.Text = "Start"
}
}
$handler_tick = {
$global:currentcnt += ($global:job | Receive-Job).Count
$percent = ($global:currentcnt / $global:totalcnt) * 100
if ($percent -lt 100) {
$progress.Value = $percent
}else{
$progress.Value = 100
$timer.Enabled = $false
$button1.Enabled = $true
$button1.Text = "Start"
$global:job | remove-job -ErrorAction SilentlyContinue
}
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 74
$System_Drawing_Size.Width = 292
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.MaximizeBox = $False
$form1.Name = "form1"
$form1.Text = "ProgressForm"
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 41
$button1.Location = $System_Drawing_Point
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 268
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 1
$button1.Text = "Start"
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($handler_button1_Click)
$form1.Controls.Add($button1)
$progress.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$progress.Location = $System_Drawing_Point
$progress.Name = "progress"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 268
$progress.Size = $System_Drawing_Size
$progress.TabIndex = 0
$form1.Controls.Add($progress)
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Timer settings
$timer.add_tick($handler_tick)
$timer.Enabled = $false
$timer.Interval = 500
#----- Show Form
$form1.ShowDialog() | out-null
# WICHTIG Timer resourcen freigeben
$timer.dispose()
regards
monoeagle