简体   繁体   中英

How to speed up the disposal of a ListView

How can I speed up the disposal of a ListView control?

A little background: this solution is using MaterialSkin, so my list of available controls is limited (there is no ListBox or DataGridView, for example). 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.

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. 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. And there, I know the ListView has to deal with the overhead of placing items. In removal, not so much.

Note: form is being displayed with ShowDialog -- so control isn't returned until the 16 seconds are up. A fall-back plan is to use Show and trigger an event when the dialog is in the process of closing.

And yes, I think displaying 51k records is bad UI, and have explained that to the client multiple times; for now, the insistence that 51k records be there stands. (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

Have you tried using databinding instead of using the Listview.Items directly? So you can set the ItemsSource to null and then (async?) empty the actual List.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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