I have a Winforms application that schedules some work using a service. The service has a callback that updates the database with the work proceedings.
Now let’s say I schedule x work items. After the x work items are all completed, I want to generate an HTML report about the work statistics. I think the only way I can check the work completion of all items is to see their completion statuses in the database.
Can someone tell me how and when I can generate the HTML report? I think I can use a thread to poll the db to see if all work completed and inform UI to generate the report, but don’t know how to implement that.
You can use BackgroundWorker component for waiting async task completed. It’s easy.
First – drag BackgroundWorker from Toolbox to your form.
Second – when you start processing (e.g. on button click event) add following code:
Next – add to DoWork event handler code that starts processing and polling database:
And last – add RunWorkerCompleted handler, which will run just after DoWork completed (i.e. all tasks updated their state in database):
Thats it. Btw BackgroundWorker could report progress during polling database. Little searching will help you how to do that 🙂