CWinThread – MSDN6翻譯交流

來源:互聯網
上載者:User

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建立的線程不能使用任何MFC的API。)

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 Members |  Base Class |  Hierarchy Chart

Sample    MFC Sample MTGDI

See Also   CWinApp, CCmdTarget

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.