Reputation: 15
In the MFC Project ,I have main thread focusing on the dialog. another worker thread focusing on receiving data from server ,parsing the data and updating the data into database.
the data from server is quite huge. so I destroy the dialog by clicking the close button while the worker thread is not finished. But the worker thread is not independent. while I delete the object create in the main thread, the worker thread can't continue , that is to say. some error like the access violation problem. (because the worker thread use the member variables in the xxxxdialog class).
the way I create a thread is AfxBeginThread, i use the method waitforsingleobject, still can not work...
I don't want to force to kill the worker thread, otherwise, it will cause memory leak...
Upvotes: 0
Views: 789
Reputation: 36
You should terminate the workthread safely before the maindlg is destroyed.
Here is the answer [Terminating a thread gracefully not using TerminateThread() ]
Upvotes: 0