tags:

views:

50

answers:

2
string[] idit = File.ReadAllLines(textBox2.Text);
foreach (string barcoutn in idit){
    barcountmax++;

}
foreach (string ids in idit){
    //do sql stuff
    barmovement++;    
    bgw1.ReportProgress(barmovement);
}


private void bgw1_ProgressChanged(object sender, ProgressChangedEventArgs e){
    progressBar1.Value = e.ProgressPercentage; 
}

My progressbar properties are set from the barcountmax for the max value and min value = 0.

I can't seem to get my progress bar to update, what am i missing?

+5  A: 

Right now, you only update at the end

foreach (string ids in idit)
{
    //do sql stuff
    barmovement++;
}
bgw1.ReportProgress(barmovement);

You need to update as you go:

foreach (string ids in idit)
{
    //do sql stuff
    barmovement++;
    bgw1.ReportProgress(barmovement);
}

You need to call ReportProgress with an int value from 0 to 100. If you're calling it with barmovement directly, this is potentially a problem. For details, see the help for ReportProgress:

percentProgress

Type: System.Int32

The percentage, from 0 to 100, of the background operation that is complete.

Reed Copsey
that was a typo in the posting, code has that inside the foreach loop though +
Mike
@Mike: Added a second possibility...
Reed Copsey
but couldn't i somehow report a total here? i mean i have like 1 million entries and i just want to know if i'm on record 103406
Mike
@Mike: Nope - BackgroundWorker always reports progress as a percentage. You need to compute a percentage, and report that.
Reed Copsey
so what am i looking for to accomplish what i need?
Mike
+1  A: 

Did you set WorkerReportsProgress to true? It is false by default.

Aaron