How do I stop a thread? I'm using ::TerminateThread within this code and the thread keeps running. Is this the correct procedure? Thanks for any help.
Code:void CPageTwo::OnBnClickedButTest() { // Click First to Start Thread // Click Again to End Thread if(!m_pThread) // Start Thread { m_pThread = AfxBeginThread(ThreadFunc, this); if(!m_pThread) { // Could not create thread return; } } else // End the thread { ::TerminateThread( m_pThread, 0 ); m_pThread = 0; } } UINT CPageTwo::ThreadFunc(LPVOID lpParam) { CPageTwo* p2 = (CPageTwo*)lpParam; for(int i = 0; i < 100; ++i) { p2->PostMessage(WM_UPDATE_PROGRESS, 0, (LPARAM)i); Sleep(2000); } return 0; }




Reply With Quote