哪个是在mfc中利用线程的最佳方法? [英] which is the best way to exploit the thread in mfc ?

查看:84
本文介绍了哪个是在mfc中利用线程的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有在MFC中使用线程的指南?有什么道路可以让gui和线程沟通?我应该在MFC上实时显示多个文档的股票图表吗?

Is there a guide to using threads in MFC ? what roads are there to make gui and thread communicate ? Should I display stock charts on multiple documents in real time which is the most efficient method on MFC ?

谢谢

推荐答案

有一件重要的事情需要记住。 在Windows中(当然,在今天的所有主要UI中),UI对象的所有绘图和所有操作都必须在创建窗口的线程中进行。 许多人没有意识到消息队列
与进程没有关联 - 它与一个线程相关联。  GDI中没有互锁,所以如果你有两个线程试图更新一个列表框,那么灾难就会随之发生。

There is one important thing to remember.  In Windows (well, in ALL of the major UIs today), all drawing and all manipulation of UI objects must take place in the thread that created the window.  Many people don't realize that the message queue is not associated with a process -- it is associated with a thread.  There is no interlocking in GDI, so if you have two threads trying to update one list box, disaster tends to ensue.

将计算密集型任务分离到一个线程很容易,只要你记得使用SendMessage(或衍生产品)发回通知来触发UI活动。

It's easy enough to spin off your computationally intensive tasks to a thread, as long as you remember to use SendMessage (or a derivative) to send notifications back to trigger UI activity.

几乎在每种情况下,用户界面都会花99%的时间等待用户 确保您没有尝试无意义地优化代码。 股票图表会更新,每10或15秒更新一次? 无论你如何绘制,这都是
而不是性能瓶颈。

In almost every case, user interfaces spend 99% of their time waiting on the user.  Make sure you're not trying to optimize code pointlessly.  A stock chart is going to update, what, every 10 or 15 seconds?  No matter how you draw it, that's not a performance bottleneck.


这篇关于哪个是在mfc中利用线程的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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