|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Speed issues with filling a list viewI was wondering how you guys would handle filling a list view with something
like 10,000 items which each have 10 sub items on them... there has to be major speed issues with that right? Yet, applications like outlook and such can retrieve and display tens of thousands of emails with virtually no performance hit at all... how would we go about getting a .NET listview to get similar performance? when I try to do what I said above, it takes about 15 seconds or more to fill it with that much information and that is just random test data... not real life from a database data either Welcome to the world of threading!
Load the visible page, then continue to load the rest in another thread. There is a good example in chapter 10 of: http://www.apress.com/book/bookDisplay.html?bID=173 The source code is available for download. Show quoteHide quote "Brian Henry" <nospam@nospam.com> wrote in message news:OMpqDhdxFHA.2228@TK2MSFTNGP11.phx.gbl... >I was wondering how you guys would handle filling a list view with >something like 10,000 items which each have 10 sub items on them... there >has to be major speed issues with that right? Yet, applications like >outlook and such can retrieve and display tens of thousands of emails with >virtually no performance hit at all... how would we go about getting a .NET >listview to get similar performance? when I try to do what I said above, it >takes about 15 seconds or more to fill it with that much information and >that is just random test data... not real life from a database data either > I do not think that it is a listview that is used; rather, I think that the
control is a datagrid. I also think that only that which is visible plus a few more are actually loaded on initial load. The rest of the data is loaded on demand to match the scrollbar. Counts, and pointers are the only thing loaded on initial load. Show quoteHide quote "Brian Henry" <nospam@nospam.com> wrote in message news:OMpqDhdxFHA.2228@TK2MSFTNGP11.phx.gbl... >I was wondering how you guys would handle filling a list view with >something like 10,000 items which each have 10 sub items on them... there >has to be major speed issues with that right? Yet, applications like >outlook and such can retrieve and display tens of thousands of emails with >virtually no performance hit at all... how would we go about getting a .NET >listview to get similar performance? when I try to do what I said above, it >takes about 15 seconds or more to fill it with that much information and >that is just random test data... not real life from a database data either > The best performance I have gotten from a ListView is via
ListView.Items.AddRange(x) where x is an array of ListViewItems. With the data volume you have, I think the way to go is a worker thread that creates an array of ListViewItems, loads data into the array, and from time to time calls AddRange and reinitializes. Be aware of the need to execute AddRange on gui thread rather than on the worker thread. On Fri, 30 Sep 2005 13:52:02 -0700, "AMercer"
<AMer***@discussions.microsoft.com> wrote: >The best performance I have gotten from a ListView is via I do agree that using AddRange is the fastest way. I will however> ListView.Items.AddRange(x) >where x is an array of ListViewItems. With the data volume you have, >I think the way to go is a worker thread that creates an array of >ListViewItems, loads data into the array, and from time to time calls >AddRange and reinitializes. Be aware of the need to execute AddRange on gui >thread rather than on the worker thread. disagree about using a worker thread since the gain is minimal. In my experience the majority of time will still be spent in the AddRange method and not building the array. Here is some modified sample code from one of my projects to use as a base. Displaying 9600 items takes 1.5 seconds (which is acceptable for me as a user of the program) on my Athlon XP 1700. private void RefreshListView() { listView.BeginUpdate(); listView.Items.Clear(); AddItemsToListView(); listView.EndUpdate(); } private void AddItemsToListView() { List<ListViewItem> items = new List<ListViewItem>(); foreach (Episode episode in filter.Execute(episodeList.Episodes)) items.Add(CreateListViewItem(episode)); listView.Items.AddRange(items.ToArray()); } private static ListViewItem CreateListViewItem(Episode episode) { ListViewItem item = new ListViewItem( new string[] { episode.OriginalAirdate.HasValue? episode.OriginalAirdate.Value.ToShortDateString():"", episode.Show.Name, episode.Season.ToString(), episode.EpisodeNumber.ToString(), episode.Title }); item.ForeColor = EpisodeForeColor(episode); item.Tag = episode; return item; } Even though I create lots of ListViewItems which contain a decent amount of subitems(5). I still spend 90% of the time in the AddRange method. -- Marcus Andrén wow you are right, doing an addrange increased our performance by a lot of
time. Before it took 4530 milliseconds to fill, now it only takes 635 milliseconds Show quoteHide quote "AMercer" <AMer***@discussions.microsoft.com> wrote in message news:E30D9BC7-BB79-476D-92D5-9038883208B5@microsoft.com... > The best performance I have gotten from a ListView is via > ListView.Items.AddRange(x) > where x is an array of ListViewItems. With the data volume you have, > I think the way to go is a worker thread that creates an array of > ListViewItems, loads data into the array, and from time to time calls > AddRange and reinitializes. Be aware of the need to execute AddRange on > gui > thread rather than on the worker thread. > "Brian Henry" <nospam@nospam.com> schrieb: You may want to use a virtual listview:>I was wondering how you guys would handle filling a list view with >something like 10,000 items which each have 10 sub items on them... there >has to be major speed issues with that right? Yet, applications like >outlook and such can retrieve and display tens of thousands of emails with >virtually no performance hit at all... how would we go about getting a .NET >listview to get similar performance? <URL:http://www.ilypsys-systems.co.uk/ils1controls.zip> Note that .NET 2.0's listview control will support a virtual mode ('VirtualMode' property) which allows to display millions of items blindingly fast. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Other interesting topics
.NET Framework Ignores Regional Settings on WinXP
How to compare objects why Assembly.LoadFrom() function does'nt load VC++ Project exe file HOW to solve ... System.Net.WebException: Connection closed Not all images are loaded correctly Manifest Resources: format programatically how to set the steps involved in enabling the ASP. how do C#.NET load VC++Project exe How does FileSystemWatcher work? Documents on .NET framework |
|||||||||||||||||||||||