How to load 100,000 list view items without application freeze?
-
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?
Чесноков
-
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?
Чесноков
Do make use of Application.DoEvents() and/or this.Refresh() it will keep your GUI live. These two functions simply force the form to be redrawn.
-
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?
Чесноков
First, putting 100,000 items in a ListView control is ridiculous. Do you really think a user wants to scroll through all that just to find a particular record?? If you add all the items to the listView all at once, there's no way to avoid the "freeze". That's because the UI thread has to handle adding those items to the ListView. it cannot be done from another thread because you can only maniplute a control on the thread that created it. You can, however, add each item tot he ListView, one a few at time, from a background thread, by Invoking a method on the UI thread to add just a few items at a time. This will give the UI thread time to handle other requests, but it'll take considerably longer to add your 100,000 items. You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
First, putting 100,000 items in a ListView control is ridiculous. Do you really think a user wants to scroll through all that just to find a particular record?? If you add all the items to the listView all at once, there's no way to avoid the "freeze". That's because the UI thread has to handle adding those items to the ListView. it cannot be done from another thread because you can only maniplute a control on the thread that created it. You can, however, add each item tot he ListView, one a few at time, from a background thread, by Invoking a method on the UI thread to add just a few items at a time. This will give the UI thread time to handle other requests, but it'll take considerably longer to add your 100,000 items. You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
A guide to posting questions on CodeProject[^]
Dave KreskowiakDave Kreskowiak wrote:
You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
Have you ever ran Windows Events on your machine? How many events are there in a list view for a couple of years e.g. windows applications :) It does not freeze as you run it either.
Чесноков
-
Do make use of Application.DoEvents() and/or this.Refresh() it will keep your GUI live. These two functions simply force the form to be redrawn.
That does not solve application freeze. You can not move the window
Чесноков
-
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?
Чесноков
-
Dave Kreskowiak wrote:
You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
Have you ever ran Windows Events on your machine? How many events are there in a list view for a couple of years e.g. windows applications :) It does not freeze as you run it either.
Чесноков
-
Dave Kreskowiak wrote:
You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
Have you ever ran Windows Events on your machine? How many events are there in a list view for a couple of years e.g. windows applications :) It does not freeze as you run it either.
Чесноков
Chesnokov Yuriy wrote:
Have you ever ran Windows Events on your machine?
What Dave was saying is not that can't be done, or even that it is particularly difficult. What he was saying - and I agree wholeheartedly - is that if you are loading 100,000 items into a listview, then your design is seriously flawed. It doesn't matter if other software does it: it is still a stupid idea and evidence that the designer / programmer is lazy. Think about it from the point of view of the user. How do you find what you want in a list of 100,000 items? If you got 50 to a page, that is 2,000 pages to scroll through. Instead, give them searches, give them filters, show the top twenty and tell them how many more there are. Does Google load all 10,000 hits into a single page? I wonder why not!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?
Чесноков
Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Monday, January 31, 2011 10:26 AM
-
Chesnokov Yuriy wrote:
Have you ever ran Windows Events on your machine?
What Dave was saying is not that can't be done, or even that it is particularly difficult. What he was saying - and I agree wholeheartedly - is that if you are loading 100,000 items into a listview, then your design is seriously flawed. It doesn't matter if other software does it: it is still a stupid idea and evidence that the designer / programmer is lazy. Think about it from the point of view of the user. How do you find what you want in a list of 100,000 items? If you got 50 to a page, that is 2,000 pages to scroll through. Instead, give them searches, give them filters, show the top twenty and tell them how many more there are. Does Google load all 10,000 hits into a single page? I wonder why not!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
OriginalGriff wrote:
How do you find what you want in a list of 100,000 items
There is scroll bar, I can scroll them all easily :) and find event I'm looking for. Filtering is another extension to consider, the problem is to load them all at once. Why Microsoft can do that and we can't? Was it the serious desing flaw in windows event viewer or not we may further argue.
OriginalGriff wrote:
Does Google load all 10,000 hits into a single page
Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem. If it hangs IE to load some of the pages with java which fits into a single window, consider what would happen with a page consisted of 10000 links.
Чесноков
-
Change your design and use VirtualMode[^] to allow fast drawing of the
ListView
irrespective of where in the view you are positioned.I must get a clever new signature for 2011.
ok, I may try that in the end
Чесноков
-
Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Monday, January 31, 2011 10:26 AM
1. log events with time column are easy to scroll 2. I tried to hide listview during items addition and then show it again, that increased performance, I will try yours methods 3. no, it does not, objects are already in the generic list with public methods e.g. time, message, keyword etc... the list view is in details view with columns to each field 4. that is not agreeble compared to 2.
Чесноков
-
Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Monday, January 31, 2011 10:26 AM
Luc Pattyn wrote:
. it is wise to use AddRange rather than Add, and
It will need to create a list of ListViewItems. Will it be faster than reporting from background worker item by item?
Чесноков
-
Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Monday, January 31, 2011 10:26 AM
Luc Pattyn wrote:
sometimes surround the entire operation with SuspendLayout/ResumeLayout
that is significantly slower than hiding the control
Чесноков
-
1. log events with time column are easy to scroll 2. I tried to hide listview during items addition and then show it again, that increased performance, I will try yours methods 3. no, it does not, objects are already in the generic list with public methods e.g. time, message, keyword etc... the list view is in details view with columns to each field 4. that is not agreeble compared to 2.
Чесноков
For logging I recommend a ListBox, it will easily handle thousands of lines per second. See here[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
For logging I recommend a ListBox, it will easily handle thousands of lines per second. See here[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
I need to display log events which are already collected in a generic list. There are thousands of them, I'd like to explore the limits. ListBox does not contain columns to show specific fields :(
Чесноков
-
OriginalGriff wrote:
How do you find what you want in a list of 100,000 items
There is scroll bar, I can scroll them all easily :) and find event I'm looking for. Filtering is another extension to consider, the problem is to load them all at once. Why Microsoft can do that and we can't? Was it the serious desing flaw in windows event viewer or not we may further argue.
OriginalGriff wrote:
Does Google load all 10,000 hits into a single page
Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem. If it hangs IE to load some of the pages with java which fits into a single window, consider what would happen with a page consisted of 10000 links.
Чесноков
Chesnokov Yuriy wrote:
There is scroll bar, I can scroll them all easily
Try scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".
Chesnokov Yuriy wrote:
Why Microsoft can do that and we can't?
You're referring to the Spy-program, where a
ListBox
is used for logging. Microsoft is using the same technique in it's Sql Profiler. The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry. Now, adding text to a collection that's displayed in a control doesn't take much time. Loading a lot of records from your database and adding them to your list will take a lot of time, especially if Windows keeps repainting after each fresh insert.Chesnokov Yuriy wrote:
Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem.
That's far-fetched, your computer won't run out of memory if Google replies with more than 50 results. It would be rediculous to assume that you're going to read over 500 results, so they send you what you're probably going to use. How often did you navigate to the second result-page?
I are Troll :suss:
-
Dave Kreskowiak wrote:
You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.
Have you ever ran Windows Events on your machine? How many events are there in a list view for a couple of years e.g. windows applications :) It does not freeze as you run it either.
Чесноков
Chesnokov Yuriy wrote:
Windows Events
Huh? If you're referring to Event Viewer, then yes, I have. And to counter, have you ever looked at ALL of those events, or just the last 100 or so?? Notice how long it takes to populate that list of 1,000 events?? I rest my case. I know it doesn't freeze. That's because it's adding all those events from a background thread, and not all at one time.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?
Чесноков
Thats Easy. just use the listview in virtual mode m8 ;) I have some listviews with over a million entries, and my app dont freeze at all. ;) Just remember to use cached items that also ups the preformance ;) Heres the guideline from MSDN http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode.aspx[^] Happy codeing
With great code, comes great complexity, so keep it simple stupid...:-\ :-\
-
Thats Easy. just use the listview in virtual mode m8 ;) I have some listviews with over a million entries, and my app dont freeze at all. ;) Just remember to use cached items that also ups the preformance ;) Heres the guideline from MSDN http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode.aspx[^] Happy codeing
With great code, comes great complexity, so keep it simple stupid...:-\ :-\