snipered

snipered

  • NA
  • 4
  • 0

Updating progressbar from different class using backgroundworker

Aug 26 2010 3:57 PM

Hi,
i have a form that contains a class with a toolstripprogressbar.
I click the button and it calls the second class.  It runs a simple loop (for now).  While this is running, its supposed to update the progressbar on the form - BUT it never seems to update the progressbar.
Any ideas?  Thanks in advance
 

private void btnSave_Click(object sender, EventArgs e)
{
/*TODO needs ammending*/
ucClient test = (ucClient)tabInstance[tbctrlMain.SelectedIndex - 1];

bgWork.WorkerReportsProgress =
true;
bgWork.DoWork += test.saveState;
bgWork.RunWorkerCompleted += workerCompleted;
bgWork.RunWorkerAsync();
}

public void

ProgressChanged(
object sender, ProgressChangedEventArgs e)
{
this.pbWork.Value = e.ProgressPercentage;
pbWork.Control.Invoke(
new MethodInvoker(delegate(){pbWork.Value = e.ProgressPercentage;}));
}


private void workerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
MessageBox.Show("done");
}

 

public void saveState(object sender, DoWorkEventArgs e)
{
BackgroundWorker saveWork = sender as BackgroundWorker;
int totalSteps = 5;
for (int i = 1; i <= totalSteps; i++)
{
saveWork.ReportProgress(i * 100 / totalSteps);
}
// blClient client = new blClient();
// client.createClient(Forename,Surname, Road, Area, City, County,Postcode, Telephone, Email);
}

Answers (3)