CWinThread

This class encapsulates a thread of execution within an application. The main thread of execution is usually provided by an object derived from CWinApp, which is derived from CWinThread. Additional CWinThread objects allow multiple threads within a specified application.

There are two general types of threads that CWinThread supports: worker threads and user-interface threads. Worker threads have no message pump. An example of a worker thread, is a thread that performs background calculations in a spreadsheet application. User-interface threads have a message pump and process messages received from the system. CWinApp and classes derived from it are examples of user-interface threads. Other user-interface threads can also be derived directly from CWinThread.

Objects of class CWinThread typically exist for the duration of the thread. If you wish to modify this behavior, set the m_bAutoDelete data member to FALSE.

The CWinThread class is necessary to make your code and MFC for Windows CE fully thread-safe. Thread-local data used by the framework to maintain thread-specific information is managed by CWinThread objects. Because of this dependence on CWinThread to handle thread-local data, any thread that uses MFC must be created by MFC for Windows CE. For example, a thread created by the run-time function _beginthread, _beginthreadex cannot use any MFC APIs.

To create a thread, call AfxBeginThread. There are two forms, depending on whether you want a worker or user-interface thread. If you want a user-interface thread, pass to AfxBeginThread a pointer to the CRuntimeClass of your CWinThread-derived class. If you want to create a worker thread, pass to AfxBeginThread a pointer to the controlling function and the parameter to the controlling function. For both worker threads and user-interface threads, you can specify optional parameters that modify priority, stack size, creation flags, and security attributes. AfxBeginThread will return a pointer to your new CWinThread object.

Instead of calling AfxBeginThread, you can construct a CWinThread-derived object and then call CreateThread. This two-stage construction method is useful if you want to reuse the CWinThread object between successive creation and terminations of thread executions.

Remarks

Windows CE supports thread priorities differently than Windows 98 and Windows NT do, so the CWinThread::SetThreadPriority and CWinThread::GetThreadPriority methods accept and return different values than they do in those versions of Windows.

Requirements

**  Windows CE versions:** 1.0 and later
  Header file: Declared in Afxwin.h
  Platform: H/PC Pro, Palm-size PC, Pocket PC

See Also

CWinThread::SetThreadPriority, CWinThread::GetThreadPriority, CWinApp, CCmdTarget, Application Architecture Classes