// Creating Thread
if (NULL == m_pThread)
m_pThread = AfxBeginThread(ThreadProc,
m_pThread->m_bAutoDelete = false;
TerminateThread forces another thread to exit. You should avoid calling it at all costs as it will stop a thread dead in it’s tracks without any chance to cleanup. This includes any CRT memory allocated.
ExitThread is for the currently running thread to stop itself nice and cleanly. When you called it above, you likely forced the main (UI) thread to exit and likely left the running threads still lingering around. Hence, your program was still running as evidenced in Task Manager. GetExitCodeThread was also likely failing since the threads had not actually exited.
But the right way to stop a thread is to cleanly signal by any clean means necessary that it should exit. Then allow the threads to exit on their own before allowing the main thread to exit.
// Deleting thread
// get the thread's exit code (I'm not sure why you need it)
BOOL bRet = GetExitCodeThread(m_pThread->m_hThread, &dwExitCode);
// cleanup the thread
m_pThread->m_hThread = NULL;
m_pThread = NULL;