CWinThread Class
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

CWinThread Class

Updated: July 2009

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




July 2009

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

Customer feedback.

© 2016 Microsoft