Hi

From the main thread of my NFC based SDi application, i am creating a UI thread. Now from within the UI thread, i am creating a worker thread that does a very crucial job.

This worker thread has the tendancy to hang in certain situations.

To handle this hang sitaution, i wait on this worker thread from my UI thread for a max of 60 seconds using WaitForSingleObject(pThread->m_hTread, 60000).

Please have a look at the code snippet:


//This is a function in my UI thread.
BOOL CDocRecover::QuickRepair()
{
---
--- //some code goes here.
---

//Now here i am creating a worker thread.

CWinThread* pThread = AfxBeginThread(Worker_ThreadSample, wordDocs);

DWORD dwReturnValue = WaitForSingleObject(pThread->m_hThread, 60000);

if(dwReturnValue ==WAIT_TIMEOUT)
{
DWORD lpExitCode = 0;
GetExitCodeThread(pThread->m_hThread, &lpExitCode);

while(TerminateInstance(TRUE)==TRUE);
if(wordApp1.m_lpDispatch)
{
wordApp1.ReleaseDispatch();
wordApp1.Quit(covFalse, covTrue, covFalse);
DeleteFile(pApp->strTargetPath);
}

if(lpExitCode==STILL_ACTIVE)
AfxEndThread((UINT)lpExitCode);
}


int dp=0;


}


Now assuming that the worker thread has hanged, after waiting for 60 seconds the control will come inside the if(dwReturnValue ==WAIT_TIMEOUT) block & worker thread will be terminated after releasing some dispatch.

Now the problem is that after the call to AfxEndThread(), the control never reaches the line int dp=0;


I DONOT KNOW WHY?

The Application has not hanged but the control never returns to the UI thread.


Please suggest


Regards