【问题标题】:Where should we write the original thread-function in a thread class我们应该在线程类中的哪里编写原始线程函数
【发布时间】:2011-01-11 18:20:42
【问题描述】:

我正在阅读 CWinThread 教程,发现从 CWinThread 派生的类可以在 AfxBeginThread 中使用。请告诉我应该在哪里(在哪个函数下)编写线程逻辑,或者哪个是 UINT MyControllingFunction(LPVOID pParam); 在 CWinThread 类中的替代方案。

问候,

约翰。

【问题讨论】:

    标签: multithreading visual-c++ mfc


    【解决方案1】:

    你好通常线程函数逻辑写在类成员函数中

    UINT CMyThread::ThreadProc( LPVOID param )
    {
      CMyClass * pInstance =  reinterpret_cast<CMyClass*>(param);
    
      return pInstance->DoMyLogic();
    }
    

    如果我理解你的问题

    【讨论】: