eflorico
eflorico

Reputation: 3629

Progress reporting from background task

I have a background task that imports files into a database. I want the user to see what is currently happening (collecting files/ importing files), which file is currently processed and how far the task has progressed. How can I do this in an easy way? The interaction between Model and Controller is so close, that I could almost put the importing code into the window's code file and change the progress bar value etc. directly. What do you think? How would you solve this problem?

Upvotes: 1

Views: 626

Answers (2)

Raj More
Raj More

Reputation: 48016

Progress bars can be misleading in a lot of cases so I suggest you be careful setting expectations.

If you do end up showing progress as a percentage of some sort do account for varying load times depending on file size.

Upvotes: 0

Thomas Levesque
Thomas Levesque

Reputation: 292445

Use a BackgroundWorker, it's perfect for this task. It can notify the UI of current progress using the ReportProgress method, which raises the ProgressChanged event on the UI thread (which means you don't have to worry about cross-thread calls and Invoke)

Upvotes: 8

Related Questions