Question on Background worker

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey guys,

I'm trying to update a progress bar for a long running process that updates
quite frequently. I also would like the GUI to remain responsive to
resizing/moving/repainting, etc.

When I use the below methods in a background worker thread the GUI doesn't
remain very responsive. Is it because the progress bar is being updated very
frequently? If I have a real process running that updates just as fast, what
can I do to keep the GUI running smoothly?

Thanks,
-Flack

======================================


private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < 50000; i++)
{
backgroundWorker1.ReportProgress((int)((i / 50000.0) * 100.0));
}
}

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

private void backgroundWorker1_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
MessageBox.Show("Done");
}
 
Flack,

Scale back on how often you report progress. Do it once every 1000
iterations of the loop instead and see what happens. Increase or
decrease the rate to throttle how often the UI should update.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top