CWinThread - MSDN6翻译交流

BUG和建议请提出,谢谢!

CWinThread

A CWinThread object represents a thread of execution within an application. The main thread of execution is usually provided by an object derived from CWinApp; CWinApp is derived from CWinThread. Additional CWinThread objects allow multiple threads within a given application.

一个CWinThread物件表现了一个应用中执行的一个线程。执行的主线程通常由一个继承自CWinApp的物件提供;CWinApp继承自CWinThread。额外的CWinThread物件允许了(给定的)应用(使用)多线程。

There are two general types of threads that CWinThread supports: worker threads and user-interface threads. Worker threads have no message pump: for example, 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.

有两种(通常的)类型的线程(被)CWinThread支持:(工作)线程和用户接口线程。工作线程没有消息pump(循环?):例如,一个电子表格应用中执行后台计算的线程。用户接口线程具有一个消息pump并且处理从系统接收到的消息。CWinApp和从其继承的类即为用户接口线程的例子。其它的用户接口线程也能直接从CWinThread继承。

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

CWinThread类的物件(的存在代表着线程的持续时期)。如果你想改变此行为,请将m_bAutoDelete设置为FALSE

The CWinThread class is necessary to make your code and MFC 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 example, a thread created by the run-time function _beginthreadex cannot use any MFC APIs.

CWinThread类,使得你的代码和MFC(具有)充分的thread-safe(线程安全)。(让framework来使用的,用以维持thread-specific信息的thread-local数据由CWinThread物件来管理。由于处理thread-local数据对于CWinThread的依赖,任何使用MFC的线程必须由MFC来创建。例如,一个由运行时函数_beginthreadex创建的线程不能使用任何MFCAPI。)

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.

要创建一个线程,(请)调用AfxBeginThread。它有两种形式,取决于你是想要一个工作线程还是一个用户接口线程。如果你想要一个用户接口线程,(请)传给AfxBeginThread一个指向你继承自CWinThread的类的CRuntimeClass的指针。如果你想创建一个工作线程,(请)传给AfxBeginThread一个指向控制函数的指针和此控制函数的参数。……

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.

For more information on CWinThread, see the articles Multithreading with C++ and MFC, Multithreading: Creating User-Interface Threads, Multithreading: Creating Worker Threads, and Multithreading: How to Use the Synchronization Classes in Visual C++ Programmer’s Guide.

Class MembersBase ClassHierarchy Chart

Sample    MFC Sample MTGDI

See Also   CWinApp, CCmdTarget

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值