Powershell how to stop progressbar





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to read data from an array and displaying a progressbar.

My goal is to stop the loop and progressbar and to do this I did it this way.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$ButtonStart.Enabled = $false
$ButtonStop.Enabled = $true
$script:CancelLoop = $false

# =============================================================
# LOOP EXCEL DATA OBJECT
# =============================================================
$Counter = 0
$ErrorCounter = 0;

foreach ($Row in $ExcelData) {

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}

$Counter++
[Int]$Percentage = ($Counter/$ExcelData.Count)*100
$ProgressBar1.Value = $Percentage
$LabelCounter.Text = "Show $Counter of " +$ExcelData.Count
[System.Windows.Forms.Application]::DoEvents()
Start-Sleep -Milliseconds 900

}

$ButtonStop.Enabled = $false
}

function ButtonStop_Click {
$ProgressBar1.Value = 0
$script:CancelLoop = $true
}


Unfortunately it does not work because after the loop has started, I try to click the stop button (even if it is enabled) nothing happens until the end of the loop.

In the past I used do-until for start-stop a progressbar but without read a array and it worked well.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$TextBoxSubject.ReadOnly = $true

$Progressbar1.Maximum = 100

$script:CancelLoop = $false
$ButtonStop.Enabled = $true
$this.Enabled = $false
$Progressbar1.Value = 0

do{

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}
$Progressbar1.PerformStep()
[System.Windows.Forms.Application]::DoEvents()
sleep -Milliseconds 900

}
until($Progressbar1.Value -eq $Progressbar1.Maximum)

$this.Enabled = $true
$ButtonStop.Enabled = $false

}


I do not understand where I'm wrong.

How could I do?

Thank you










share|improve this question























  • Is this for WPF? I was trying to reproduce it to debug.

    – Tyler Szabo
    Nov 17 '18 at 1:50











  • @TylerSzabo - Is for WinForms

    – Gus
    Nov 17 '18 at 9:30


















0















I'm trying to read data from an array and displaying a progressbar.

My goal is to stop the loop and progressbar and to do this I did it this way.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$ButtonStart.Enabled = $false
$ButtonStop.Enabled = $true
$script:CancelLoop = $false

# =============================================================
# LOOP EXCEL DATA OBJECT
# =============================================================
$Counter = 0
$ErrorCounter = 0;

foreach ($Row in $ExcelData) {

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}

$Counter++
[Int]$Percentage = ($Counter/$ExcelData.Count)*100
$ProgressBar1.Value = $Percentage
$LabelCounter.Text = "Show $Counter of " +$ExcelData.Count
[System.Windows.Forms.Application]::DoEvents()
Start-Sleep -Milliseconds 900

}

$ButtonStop.Enabled = $false
}

function ButtonStop_Click {
$ProgressBar1.Value = 0
$script:CancelLoop = $true
}


Unfortunately it does not work because after the loop has started, I try to click the stop button (even if it is enabled) nothing happens until the end of the loop.

In the past I used do-until for start-stop a progressbar but without read a array and it worked well.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$TextBoxSubject.ReadOnly = $true

$Progressbar1.Maximum = 100

$script:CancelLoop = $false
$ButtonStop.Enabled = $true
$this.Enabled = $false
$Progressbar1.Value = 0

do{

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}
$Progressbar1.PerformStep()
[System.Windows.Forms.Application]::DoEvents()
sleep -Milliseconds 900

}
until($Progressbar1.Value -eq $Progressbar1.Maximum)

$this.Enabled = $true
$ButtonStop.Enabled = $false

}


I do not understand where I'm wrong.

How could I do?

Thank you










share|improve this question























  • Is this for WPF? I was trying to reproduce it to debug.

    – Tyler Szabo
    Nov 17 '18 at 1:50











  • @TylerSzabo - Is for WinForms

    – Gus
    Nov 17 '18 at 9:30














0












0








0








I'm trying to read data from an array and displaying a progressbar.

My goal is to stop the loop and progressbar and to do this I did it this way.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$ButtonStart.Enabled = $false
$ButtonStop.Enabled = $true
$script:CancelLoop = $false

# =============================================================
# LOOP EXCEL DATA OBJECT
# =============================================================
$Counter = 0
$ErrorCounter = 0;

foreach ($Row in $ExcelData) {

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}

$Counter++
[Int]$Percentage = ($Counter/$ExcelData.Count)*100
$ProgressBar1.Value = $Percentage
$LabelCounter.Text = "Show $Counter of " +$ExcelData.Count
[System.Windows.Forms.Application]::DoEvents()
Start-Sleep -Milliseconds 900

}

$ButtonStop.Enabled = $false
}

function ButtonStop_Click {
$ProgressBar1.Value = 0
$script:CancelLoop = $true
}


Unfortunately it does not work because after the loop has started, I try to click the stop button (even if it is enabled) nothing happens until the end of the loop.

In the past I used do-until for start-stop a progressbar but without read a array and it worked well.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$TextBoxSubject.ReadOnly = $true

$Progressbar1.Maximum = 100

$script:CancelLoop = $false
$ButtonStop.Enabled = $true
$this.Enabled = $false
$Progressbar1.Value = 0

do{

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}
$Progressbar1.PerformStep()
[System.Windows.Forms.Application]::DoEvents()
sleep -Milliseconds 900

}
until($Progressbar1.Value -eq $Progressbar1.Maximum)

$this.Enabled = $true
$ButtonStop.Enabled = $false

}


I do not understand where I'm wrong.

How could I do?

Thank you










share|improve this question














I'm trying to read data from an array and displaying a progressbar.

My goal is to stop the loop and progressbar and to do this I did it this way.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$ButtonStart.Enabled = $false
$ButtonStop.Enabled = $true
$script:CancelLoop = $false

# =============================================================
# LOOP EXCEL DATA OBJECT
# =============================================================
$Counter = 0
$ErrorCounter = 0;

foreach ($Row in $ExcelData) {

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}

$Counter++
[Int]$Percentage = ($Counter/$ExcelData.Count)*100
$ProgressBar1.Value = $Percentage
$LabelCounter.Text = "Show $Counter of " +$ExcelData.Count
[System.Windows.Forms.Application]::DoEvents()
Start-Sleep -Milliseconds 900

}

$ButtonStop.Enabled = $false
}

function ButtonStop_Click {
$ProgressBar1.Value = 0
$script:CancelLoop = $true
}


Unfortunately it does not work because after the loop has started, I try to click the stop button (even if it is enabled) nothing happens until the end of the loop.

In the past I used do-until for start-stop a progressbar but without read a array and it worked well.



function ButtonStart_Click {

$LabelCounter.visible = $true
$ProgressBar1.Visible = $true
$TextBoxSubject.ReadOnly = $true

$Progressbar1.Maximum = 100

$script:CancelLoop = $false
$ButtonStop.Enabled = $true
$this.Enabled = $false
$Progressbar1.Value = 0

do{

if($script:CancelLoop -eq $true){
$progressbar1.Value = 0
break;
}
$Progressbar1.PerformStep()
[System.Windows.Forms.Application]::DoEvents()
sleep -Milliseconds 900

}
until($Progressbar1.Value -eq $Progressbar1.Maximum)

$this.Enabled = $true
$ButtonStop.Enabled = $false

}


I do not understand where I'm wrong.

How could I do?

Thank you







powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 23:18









GusGus

4371620




4371620













  • Is this for WPF? I was trying to reproduce it to debug.

    – Tyler Szabo
    Nov 17 '18 at 1:50











  • @TylerSzabo - Is for WinForms

    – Gus
    Nov 17 '18 at 9:30



















  • Is this for WPF? I was trying to reproduce it to debug.

    – Tyler Szabo
    Nov 17 '18 at 1:50











  • @TylerSzabo - Is for WinForms

    – Gus
    Nov 17 '18 at 9:30

















Is this for WPF? I was trying to reproduce it to debug.

– Tyler Szabo
Nov 17 '18 at 1:50





Is this for WPF? I was trying to reproduce it to debug.

– Tyler Szabo
Nov 17 '18 at 1:50













@TylerSzabo - Is for WinForms

– Gus
Nov 17 '18 at 9:30





@TylerSzabo - Is for WinForms

– Gus
Nov 17 '18 at 9:30












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346617%2fpowershell-how-to-stop-progressbar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346617%2fpowershell-how-to-stop-progressbar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python