pisceswzh
Well-known member
- Joined
- Mar 19, 2007
- Messages
- 96
- Programming Experience
- 1-3
Hi,
In my application, I use the BackgroundWorker to load the data from the database.
I use the BackgroundWorker DoWork event to load the data from the database to a datatable and in the BackgroundWorker RunWorkerCompleted event to assign the datatable to the datasource property of a datagrid.
The problem is if the user close the form while the DoWork event is still in process and when the event is done, the RunWorkerCompleted starts and tries to assign the datatable to the datasource property of the datagrid which has been no longer existed (since the form has been closed).
Is there a way to stop all the BackgroundWorker when the form is closed or is there a better approach in my situation?
Thanks!
In my application, I use the BackgroundWorker to load the data from the database.
I use the BackgroundWorker DoWork event to load the data from the database to a datatable and in the BackgroundWorker RunWorkerCompleted event to assign the datatable to the datasource property of a datagrid.
The problem is if the user close the form while the DoWork event is still in process and when the event is done, the RunWorkerCompleted starts and tries to assign the datatable to the datasource property of the datagrid which has been no longer existed (since the form has been closed).
Is there a way to stop all the BackgroundWorker when the form is closed or is there a better approach in my situation?
Thanks!