multithreading - 如果ListView中有许多记录是从线程中添加的,则窗口会卡住

标签 multithreading delphi listview delphi-xe

我的程序在单独的线程上执行“繁重的”任务(搜索文件并查找签名)。每个任务都使用PostMessage来调用将记录添加到ListView的过程。

问题是,当ListView(通常)显示许多记录时,我的窗口将冻结。看来我的程序在尖叫要求Application.ProcessMessages。仅进度栏仍在移动。操作完成后,一切恢复正常。

如果删除添加记录的操作,则程序的运行将顺利进行。

你有什么主意吗?

最佳答案

我们曾经达到了可以将多少条消息发布到消息队列的限制。您极有可能也达到了此限制。

MSDN

There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources.



The Best Synchronization is No Synchronization

The problem with PostMessage to the main GUI thread is that you can "saturate" the main GUI message pump, and interfere with WM_TIMER and WM_PAINT messages (these messages are only dispatched if the message queue is empty, and PostMessage means that the queue might never be empty. In addition, there is a nominal limit of 10,000 messages in the input queue; after that, PostMessage will discard the message and return FALSE. In addition, even if the 10,000 limit is not hit, even a few hundred messages can mean that the user sees poor response to keyboard and mouse input, an unacceptable situation.

关于multithreading - 如果ListView中有许多记录是从线程中添加的,则窗口会卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5322302/

相关文章:

linux - Linux 和 Windows 中的多线程模型

delphi - 如何优雅地关闭 Indy10 ServerSocket 实例?

android - 在 Android 中制作一个弹跳的 ListView

java - 如何使用android中的recyclerview和数据库将位置明智的对象数据从一个 Activity 传递到另一个 Activity

Java多客户端聊天应用程序-发送消息问题

java - Gstreamer Tee/队列多流水线

c# - 快速增加内存使用率C#

delphi - 为什么我的结构查看器 Pane 中存在错误,但编译时却没有错误?

Delphi:注销应用程序时表单无法释放时该怎么办

java - ListView 适配器从 LinkedHashSet<UserItem> 获取信息。如何将其中一个 UserItems 传递到下一个 Activity