MFC主线程等待另一个线程结束

发布于 2024-12-27 21:19:58 字数 506 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2025-01-03 21:19:58

所以编写代码来做到这一点。弹出一个对话框。表明排序正在进行。做任何你想做的事。让其他线程在完成后向您的线程发送信号,例如使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文