Click to See Complete Forum and Search --> : How to start a another worker thread in a worker thread?


Apal
July 23rd, 2005, 12:12 PM
I want to start another worker thread in a worker thread.
But the worker thread never starts.

Here is the code:

UINT Thread2(LPVOID pParam)
{
AfxMessageBox("Thread Start");
return 0;

}


UINT Thread1(LPVOID pParam)
{
..........;
..........;

AfxBeginThread(Thread2, THREAD_PRIORITY_NORMAL, 0, 0, NULL)
..........;
..........;
return 0;

}

How to start a another worker thread in a worker thread?
Thanks.

golanshahar
July 23rd, 2005, 12:29 PM
i dont know what exactly you are doing but i tested that code and it worked fine i got both message box from theard1 and thread2

UINT Thread2(LPVOID pParam)
{
AfxMessageBox("Thread2 Start");
return 0;
}


UINT Thread1(LPVOID pParam)
{
AfxMessageBox("Thread1 Start");
AfxBeginThread(Thread2, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
return 0;

}

// when i click on ok button theard1 start working and inside activating theard2
void CtestDlg::OnOK()
{
AfxBeginThread(Thread1, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
}


so i dont know why its not working for you :confused:

anyway you can look at that FAQ (http://www.codeguru.com/forum/showthread.php?t=312452&highlight=AfxBeginThread) to learn more.
Cheers

Andreas Masur
July 23rd, 2005, 12:39 PM
[ Redirected thread ]

Apal
July 23rd, 2005, 09:53 PM
You are right. It does work.
I found that I made a stupid mistake in other codes which causes the problem.

Thanks.