المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Win7 - worker thread freeze on call to WaitForSingleObject



C++ Programming
02-21-2012, 05:00 PM
Hi All.

I call the following when I need to save a report in my MFC base program:
m_pEndThread = AfxBeginThread(Save2CWGCoilRep, &m_CoilRep[iCRepPos], THREAD_PRIORITY_NORMAL,0,0);

UINT Save2CWGCoilRep(LPVOID pParam)
{

I use CStdioFile to them save data to file

}


Then before I save another report, I will call

if(m_pEndCoilThread != NULL)
::WaitForSingleObject(m_pEndCoilThread->m_hThread, INFINITE);

to see if the thread is finished before calling again to save another report. And if not just wait. It seems in Win7 now, this call will not exit so that the program will just freeze. It does not freeze all the time, seems random. In WinXP, the same program seems not to have this problem. I am not sure what I am missing.

Any help or suggestion will be appreciated. Thanks!

Stan the man