Click to See Complete Forum and Search --> : Thread Problem


DarkLizener
December 13th, 2004, 03:01 PM
Hi
I've got a class CDataProcess that provides the methodes to input data to an access database using ADO. While inputting the data a status dialog showing the progress is visible. BUT: How can I stop this process (e.g. via a STOP button on the status dialog). I figured it could be useful to begin a new thread so I did this:UINT Process(LPVOID pParam)
{
CDataProcess* p = (CDataProcess*)pParam;
p->ProcessData();
}
....
void CDataProcess::ProcessData(...)
{
thread = AfxBeginThread(Process,this);
}
"thread" declared in the class
This works fine as long as you don't suspend the thread. If you do this for example through the StatusDialog (that is also declared in the CDataProcess)void CStatusDlg::OnAbort()
{
CMainWnd* p = (CMainWnd*)GetParent();
p->dataproc.thread->SuspendThread();
}
the MainWnd holds a CDataProcess variable and is the parent of the StatusDialog.
Propably I made a whole mistakes but please help me. WHY do I get an error when I stop the thread????? It stops and then peng!

Andreas Masur
December 13th, 2004, 03:12 PM
[ Moved thread ]

Andreas Masur
December 13th, 2004, 03:16 PM
Well...one thing that I do not understand from your code is that you basically calling the function 'ProcessData()' from inside the thread. This function however, is the one that created the thread...so based on this, you would recursively creating thrads... :confused:

The other question would be hwo you would like to setup the logic...from my understanding the status dialog should be responsible for the thread...in other words, it should contain the 'CDataProcess' instance. Furthermore...why do you want to suspend the thread? It rather sounds that you want to be able to stop the thread...