简体   繁体   English

将项目添加到列表控件时,UI被冻结

[英]UI is freeze while adding items to list control

My app is freeze while I click the button to add items to list control. 单击按钮将项目添加到列表控件时,我的应用程序处于冻结状态。 I'm doing it simple: 我做的很简单:

for (unsigned i = 1; i < 15000;++i)
{
  listcontrol1.InsertItem(i, L"item list");
}

I also tried using a background thread but the same results. 我也尝试使用后台线程,但结果相同。 Any idea how to do this correctly without blocking the user interface ? 任何想法如何正确地做到这一点而不阻塞用户界面?

pouring 15k messages into the message pump is going to be slow. 将15k消息倒入消息泵将很慢。

Better use a virtual list control with proper caching. 最好使用带有适当缓存的虚拟列表控件 See the VListVW Sample in %Windows SDK Dir%\\Samples\\winui\\controls\\common\\vlistvw for working code. VListVW样品在%Windows SDK的迪尔%\\样本\\ winui \\控件\\ COMMON \\ vlistvw的工作代码。

As Sheng Jiang stated the virtual list is the best solution for such a great list. 正如盛江所说,虚拟列表是此类列表的最佳解决方案。 But you can improve the performance avoiding control paintings during insertion: 但是您可以提高性能,避免在插入过程中进行绘画控制:

listcontrol1.SetRedraw(FALSE);
for (unsigned i = 1; i < 15000; ++i)
{
    listcontrol1.InsertItem(i, L"item list");
}
listcontrol1.SetRedraw(TRUE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM