How to implement progress bar and backgroundworker for database calls C#?

Posted by go-goo-go on Stack Overflow See other posts from Stack Overflow or by go-goo-go
Published on 2009-08-11T12:08:44Z Indexed on 2010/04/07 14:53 UTC
Read the original article Hit count: 852

How to implement progress bar and backgroundworker for database calls C#?

I do have some methods that deal with large amounts of data. They do last a lot, so in my windows application, i wanna do something to tell users that the data are being processed.

So i thought of using progress bar or status strip label, but since there is a single ui thread, the thread where the database-dealing methods are executed, ui controls are not updated, so progress bar or status strip label are useless to me.

I've already seen some examples, but they deal with for-loops, ex:

for(int i = 0; i < count; i++){ System.Threading.Thread.Sleep(70); // ... do analysis ... bgWorker.ReportProgress((100 * i) / count);}

private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e){ progressBar.Value = Math.Min(e.ProgressPercentage, 100);}

Can anybody give an example where I can use a method call, not a for-loop, and let the progress bar run while this method is executing???

thnx in advance, any help and hint is highly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about progressbar