In my WPF application - I have a Listview with a Gridview inside. A user is able to add files to this list.
The gridview should allow me to have quite rich "rows", each row showing file name, extra application detail and most importantly a progress bar. Each row in the gridview is databound to a business object in a collection, and specifically the object has a property "Progress" which is bound to the progress bar.
I need to process each file, extract data and send the data to a web service and I would like to display the progress for each file in it's respective progress bar as I work through the collection of files.
Initially I started off with a simple loop containing the processing logic which periodically updated the "Progress" field for each row and noted that the UI didn't update very well.
I then moved the processing logic in the loop to a BackgroundWorker which modified the business object "Progress" field, and because the UI thread was not working so hard - it was a lot more responsive.
However due to the asynchronous nature of BackgroundWorker, it started multiple BackgroundWorkers (one for each row) virtually all at once as the loop spun out. All my progress bars started progressing...
What would be the best approach to limit it to only 2-3 BackgroundWorkers going at once? Or even leave it at one BackgroundWorker - and it doesn't start until the previous one is completed? How can I introduce a dependency so that in essence all the BackgroundWorkers are synchronous?