wait for thread to finish
Situation:
I have a program (prog1) that needs to call some command line programs (prog2), and it needs to wait for them to finish in order to proceed with another tasks.
Right now i'm using a loop receiving the messages from the thread, which increases cpu utilization of the prog1.
Is there a way to sending prog1 to a blocked state and awake it when prog2 finishes?
I know how to do it in linux with forked processes, but i'm a bit novice when it comes to windows and threads.
This is what i'm doing right now:
Code:
CreateProcess(NULL,"COBASQL entcobol.cob salsql.sql",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&siInfo,&piInfo);
EsperaATerminacionProceso(piInfo.hThread);
And the waiting function:
Code:
void CTransftpDlg::EsperaATerminacionProceso(HANDLE hThread)
{
DWORD dwRet;
MSG msg;
do
{
dwRet = ::MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
if (dwRet != WAIT_OBJECT_0)
{
while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} while ((dwRet != WAIT_OBJECT_0) && (dwRet != WAIT_FAILED));
}
Thanks in advance.