带有多个线程的vc ++对话框 [英] vc++ dialog with multiple threads

查看:77
本文介绍了带有多个线程的vc ++对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我使用Visual Studio 2013进行基于Dialog的mfc applciation。

Hi I have Dialog based mfc applciation using visual studio 2013.

Dialog包含多个控件。它有两个线程 - 主要ui线程和工作线程

Dialog contains multiple controls. It has two threads - main ui thread and worker thread

在特定控件中(某些静态测试) 我必须显示一些计数(例如生产的汽车数量 

和所生产的自行车数量以及总数)。  实际上这些计数是由工作人员提供的。 

and Number of Bikes prodcued, and total ). Actually these counts are given by worker thread. 

工人线程连续给出计数(即实时数据)

Worker thread continuously gives the counts (that is live data)

我必须根据这些数据从主线程更新UI。

I have to update UI from main thread based on these data lively.

请帮我设计一下这个用例。我的ui包含多个控件。我不想阻止UI

Please help me to design this use case. My ui contains multiple controls. I don't want to block the UI

如何将数据(计数)从工作线程传递到主线程?如何避免主线程中的阻塞?

How to pass the data(counts) from worker thread to main thread? how to avoid block in main thread?

是否需要队列或其他线程?

Is there any need for queue or another thread?

那就是用户界面会有点像

 生产的汽车数量:10 

 自行车生产数量:20

总计:30




推荐答案

您可以使用PostMessage将私有消息从工作线程发布到UI线程的窗口句柄。 这是完全安全的,不会阻止UI线程或工作线程。  UI线程的对话框过程将处理私有的
消息,并在收到它们时更新对话框控件。
You can use PostMessage to post private messages from the worker thread to the UI thread's window handle.  This is completely safe and does not block the UI thread or the worker thread.  The UI thread's dialog procedure would handle the private messages and update the dialog box controls when it receives them.


这篇关于带有多个线程的vc ++对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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