延迟使用postmessage从工作线程更新GUI线程 [英] Delaying updating of GUI thread from worker threads with postmessage

查看:141
本文介绍了延迟使用postmessage从工作线程更新GUI线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用 PostMessage 从工作线程更新GUI线程但不使用睡眠之前放一些延迟?



接收来自套接字的事件完全不同步。

有时连接中会有突发,必须有一些延迟以避免泛滥GUI线程。



在性能方面达到这个目标的最佳方法是什么?



我尝试了什么:



将数据放入某种队列列表,然后让GUI线程每隔x秒循环并更新自身,但这需要锁定,因此它是线程安全的。

How can i put some delay before updating the GUI thread from worker threads using PostMessage but not using sleep?

The receiving of events from sockets are completely out of sync.
Sometimes there are bursts in connections and there must be some sort of delay to avoid flooding the GUI thread.

What is the best way to achieve this in terms of performance?

What I have tried:

Put the data in some sort of queue list then let the GUI thread loops each x seconds and update itself but that requires lock so it would be thread-safe.

推荐答案

是的;使用并发队列和计时器。



C++并发队列 [ ^ ]



C ++中的简单计时器 - Fluent C ++ [ ^ ]
Yes; use a concurrent queue and a timer.

C++ Concurrent Queues[^]

A Simple Timer in C++ - Fluent C++[^]


使用简单的 SetTimer API



提示:使用 PostThreadMessage 以避免GUI问题。
Use the simple SetTimer API of Windows.

Tip: use PostThreadMessage to avoid GUI problems.


我个人非常怀疑你是否可以充斥GUI线程如此重要以至于这将是一件坏事。



如果你重新开始ally认为你需要然后我会在FIFO中排队更新消息并让GUI在你想要的时候卸载它们。如果不出意外,它将最大限度地减少对工人的阻碍。
Personally, I seriously doubt that you could flood the GUI thread so heavily that it would be a bad thing.

If you really think you need to then I would queue the update messages in a FIFO and have the GUI unload them when you want it to. If nothing else, it will minimize blocking of the workers.


这篇关于延迟使用postmessage从工作线程更新GUI线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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