MFC并行功能 [英] MFC parallel function

查看:87
本文介绍了MFC并行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上课了,就像这样



I have class and that's like this

class mySample
{
  Cobject * cloneNode;
  std::list<Cobject *>cloneList;

}



和并行处理如下代码。

但是 仅在执行时执行只有一个cbobject

如果clonelist有两个或更多... OnPlay功能不起作用。




and parallel processing as following code.
But It only executes when there is only one cbobject.
if clonelist have two or more... OnPlay function doesn't work.

function OnPlay(bool status, const CString& str ){

   if(pDC==NULL){
       CMainFrame * pFrame = (CMainFrame*)AfxGetMainWnd();
       CChildFrame *pChild = (CChildFrame*)pFrame->GetActiveFrame();
       CButterFlyEditorView *pView = (CButterFlyEditorView*)pChild->GetActiveView();
   ...

}





VStudio说

pChild 0xccccccc {hWnd = ???}

pFrame 0x00000000< null>

这个0x0984f ... {hWnd = 0x000000< null>}



你能告诉我吗?

感谢您的时间。



我的尝试:





VStudio says
pChild 0xccccccc{hWnd=???}
pFrame 0x00000000<null>
this 0x0984f...{hWnd=0x000000<null>}

Can you advise me?
thanks for your time.

What I have tried:

parallel_for_each(CloneList.begin(), CloneList.end(), [&](Cobject* cloneNode) {
    cloneNode->OnPlay(file_status, m_ PathName);
});

推荐答案

您的帖子中已有解释:pFrame 0x00000000



阅读文档总是一个好主意。在 AfxGetMainWnd 的文本中,您可以已阅读
The explanation is already in your post: pFrame 0x00000000

Reading the documentation is always a good idea. In the text of AfxGetMainWnd you may had read
"If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call."

并且您创建的线程没有主窗口。



您必须从主线程中获取所需的值作为线程函数的输入参数。 Windows也是iOS的操作系统,在主线程中运行primary。所以从来没有从其他线程访问系统元素是个好主意。这总是需要很好的实现。

And your created threads have NO main window.

You must make the needed values from the primary thread as input parameters of your threading function. Windows is an operating system as iOS too) that run primary in the main thread. So it is never a good idea to access system elements from other threads. This ALWAYS needs excellent implementation.


这篇关于MFC并行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆