MFC主线程等待另一个线程结束
我正在尝试使用 MFC 创建一个工具。这个工具的主要工作是对数据进行排序。嗯,我发现当工具排序时,由于只有主线程;因此,在进行排序工作时,无法移动或单击任何对话框。因此,我创建了另一个线程来进行排序工作并且工作正常。
但是使用线程后又出现了一个问题。我不知道如何让主线程等待排序线程。我想在排序线程完成后做一些事情,但现在,主线程只是进入下一个过程,而不等待排序线程完成其工作。
这是片段
AfxBeginThread(processfiles, tVals) // A thread do its work.
// below I want to do something with the result I got from the thread above.
//But main thread just do its work separately without waiting for the thread to finish its work.
。
请帮忙谢谢!!
I am trying to use MFC to create a tool. This tool main job is to sort data. Well, I found that when the tool is sorting, since there is only main thread; therefore, while it is doing sorting work, no dialog boxes can be moved or clicked. Hence, I created another thread to do sorting work and works fine.
But there is another problem after I used a thread. I don't how to make main thread to wait for the sorting thread. I want to do something after sorting thread is done, but right now, main thread just moves onto the next procedures without waiting for sorting thread to finish its work.
Here is snippet
AfxBeginThread(processfiles, tVals) // A thread do its work.
// below I want to do something with the result I got from the thread above.
//But main thread just do its work separately without waiting for the thread to finish its work.
.
please help thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以编写代码来做到这一点。弹出一个对话框。表明排序正在进行。做任何你想做的事。让其他线程在完成后向您的线程发送信号,例如使用
PostMessage
向您发送消息。So write code to do that. Pop up a dialog box. Indicate that the sorting is taking place. Do whatever you want. Have the other thread send your thread a signal when it's done, say by sending you a message with
PostMessage
.