简体   繁体   English

如何加速一个ListView的处理

[英]How to speed up the disposal of a ListView

How can I speed up the disposal of a ListView control?如何加快 ListView 控件的处理?

A little background: this solution is using MaterialSkin, so my list of available controls is limited (there is no ListBox or DataGridView, for example).一点背景:这个解决方案使用的是 MaterialSkin,所以我的可用控件列表是有限的(例如,没有 ListBox 或 DataGridView)。 Second, the list has an unreasonably large number of items (51k on average, one or two columns, depending on settings), so I'm not expecting lightning speeds, but also not what I'm seeing.其次,该列表包含大量不合理的项目(平均为 51k,一列或两列,具体取决于设置),所以我不期望闪电般的速度,但也不是我所看到的。

When the form is closing, I don't need anything from the list.当表单关闭时,我不需要列表中的任何内容。 It's served its purpose and can just go away.它达到了目的,可以离开了。 Here is what I've tried:这是我尝试过的:

Close();                    --- 16 seconds (just closing the form)

MyListView.Dispose();       --- 16 seconds

MyListView.Items.Clear();   --- 16 seconds

MyListView.Clear();         --- 17 seconds

MyListView.BeginUpdate();
MyListView.Items.Clear();   --- 16 seconds

Effectively, every option I've tried is ~16 seconds to get rid of the list.实际上,我尝试过的每个选项都需要大约 16 秒才能摆脱列表。 Now, it takes about 16 seconds to populate the list, something I'm also looking into -- but at least there the time is somewhat justified in that I'm overloading this poor list with too many records.现在,填充列表大约需要 16 秒,我也在研究这一点——但至少在那里时间有点合理,因为我用太多记录使这个糟糕的列表过载。 And there, I know the ListView has to deal with the overhead of placing items.在那里,我知道 ListView 必须处理放置项目的开销。 In removal, not so much.在移除方面,没有那么多。

Note: form is being displayed with ShowDialog -- so control isn't returned until the 16 seconds are up.注意:表单正在与 ShowDialog 一起显示——因此在 16 秒结束之前不会返回控件。 A fall-back plan is to use Show and trigger an event when the dialog is in the process of closing.后备计划是使用 Show 并在对话框关闭过程中触发事件。

And yes, I think displaying 51k records is bad UI, and have explained that to the client multiple times;是的,我认为显示 51k 记录是糟糕的 UI,并且已经多次向客户端解释了这一点; for now, the insistence that 51k records be there stands.现在,坚持 51k 记录存在。 (I did add a full text search, otherwise...) (我确实添加了全文搜索,否则...)

How about just hiding your listview?隐藏你的列表视图怎么样? Try setting it's visible property to false and when you don't need listview anymore try to close form without clearing your listview尝试将它的可见属性设置为 false,当您不再需要列表视图时尝试关闭表单而不清除您的列表视图

Have you tried using databinding instead of using the Listview.Items directly?您是否尝试过使用数据绑定而不是直接使用 Listview.Items? So you can set the ItemsSource to null and then (async?) empty the actual List.因此,您可以将 ItemsSource 设置为 null,然后(异步?)清空实际列表。

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

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