CWinThread Class

Represents a thread of execution in an MFC application.

class CWinThread : public CCmdTarget


There are two ways to create a thread in MFC. You can call AfxBeginThread, which returns a pointer to the new CWinThread object. When you use AfxBeginThread, the CWinThread object is deleted by default when the thread terminates. To prevent deletion, pass the CREATE_SUSPENDED flag to AfxBeginThread to suspend the thread after it is created, then set CWinThread::m_bAutoDelete to FALSE and call CWinThread::ResumeThread.

You can also create a thread by using the new operator to construct a CWinThread object and calling CWinThread::CreateThread. Use this process if you want to use the CWinThread object to create another thread after the thread terminates.

You cannot access MFC libraries in a thread that you created by using _beginthread, _beginthreadex or CreateThread.

For more information about multithreading in MFC, see the following topics:


Header: afxwin.h

See Also


CCmdTarget Class

Hierarchy Chart

CWinApp Class


Other Resources

CWinThread Members


Change History




July 2009

Clarified the two methods of thread creation in MFC. Added cross-references.

Customer feedback.