This is a migrated thread and some comments may be shown as answers.

RadListView - performance and updating the GUI

3 Answers 275 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 11 May 2015, 12:09 PM

Hi,

we're developing a WinForms application with Telerik Controls (or rather update an older application of ours). In this app, we use different ListViews and we often encounter performance issues. We've found workarounds and performance improvements for the lower thousands (adding up to ~2000 items), which is fine, but there can be cases when the app need to load 10k items. It's not the normal case but it can happen every so often.

Now the improvements we made (e.g. using AddRange instead of Add) are still noticeable here, but it still takes about the ListView about 90 sec to load 9k items (with a small icon and text). That in and of itself is not the problem - sometimes it takes time to load so many items and since this an administration tool, we think our users could handle that.

The problem is that this is happening (or at least it seems so) when the ListView is rendering the items. That means it happens on the UI thread, which on the other hand means the app is not responding while the ListView is loading. Now that is something that needs to fixed, since I don't think that it is possible to lower the loading time to an unnoticeable level. I already tried to make the method asynchronous (public async void...) and use the await keyword but there are many complications if the user resumes to click around in the application. We'd have to make many architectural changes to make this work properly and that would cost too much time.

Is there any way to inform the user that the ListView is still loading without breaking the UI? Animated loading symbols would be fine but since the UI thread is blocked in this case, this wouldn't help much either. Any ideas?

Thanks and regards,

Steve.

PS: For reference, at the moment we load the ListView items like this, which seems to be the fastest way (we found):

01.            this.listViewGroup.Items.AddRange(__result.Select(
02.                groupResult =>
03.                {
04.                    var __lvdi = new ListViewDataItem();
05. 
06.                    //Do some work to transform the groupResult item into a ListViewDataItem
07.​                           //This takes almost no time at all (a fraction of a second)
08. 
09.                    return __lvdi;
10.                }).ToArray());

3 Answers, 1 is accepted

Sort by
0
Hugues
Top achievements
Rank 1
answered on 11 May 2015, 03:34 PM
You should use BeginUpdate before removing and adding new items and EndUpdate after you are done. That way the  listview is not updating for every item added.
0
Steve
Top achievements
Rank 1
answered on 11 May 2015, 03:37 PM
Already tried that approach, sadly there seems to be no noticeable difference in perfomance.
0
Dimitar
Telerik team
answered on 12 May 2015, 12:44 PM
Hi Steve,

Thank you for writing. 

I want to mention that Hughes is correct and you should enclose the items adding within a Begin/End update block. I have tested this and adding 9000 items takes less than a 100 milliseconds on my side (see the attached video). So there must be something else that is causing such delay on your side. This is why I want to kindly ask you to send us the entire code that is used for the items creation. 

Perhaps better approach would be to create a separate method that prepares all the data for the items (since this operation is not connected with the UI it can be executed on a separate thread). Once the data is ready you can create and add the items which would not take much time. Here is the code I have used for the test:
private void radButton1_Click(object sender, EventArgs e)
{
    Stopwatch sw = new Stopwatch();
 
    sw.Start();
    radListView1.BeginUpdate();
 
    AddItems(9000);
 
    radListView1.EndUpdate();
    sw.Stop();
    Console.WriteLine(sw.ElapsedMilliseconds);
}
 
void AddItems(int count)
{
    Image img = Image.FromFile(@"C:\img\delete.png");
    for (int i = 0; i < count; i++)
    {
        radListView1.Items.Add(new ListViewDataItem("Item " + i) { Image = img });
    }
}

I am looking forward to your reply.

Regards,
Dimitar
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
ListView
Asked by
Steve
Top achievements
Rank 1
Answers by
Hugues
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or