Click here to Skip to main content
15,913,685 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Not Active31-Jan-11 12:13
mentorNot Active31-Jan-11 12:13 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Fabio Franco1-Feb-11 4:08
professionalFabio Franco1-Feb-11 4:08 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Dave Kreskowiak31-Jan-11 7:34
mveDave Kreskowiak31-Jan-11 7:34 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 9:56
professionalChesnokov Yuriy31-Jan-11 9:56 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Fabio Franco1-Feb-11 3:17
professionalFabio Franco1-Feb-11 3:17 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy1-Feb-11 3:39
professionalChesnokov Yuriy1-Feb-11 3:39 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Fabio Franco1-Feb-11 3:52
professionalFabio Franco1-Feb-11 3:52 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Euhemerus1-Feb-11 6:52
Euhemerus1-Feb-11 6:52 
Dave Kreskowiak wrote:
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.


What about using a delegate on the background worker thread? This worked for me.

' Because we run our routine that gets the selected class's properties on a background thread using the
' BackgroundWorker component, we can't update our listview directly using this thread, if we try, we get
' a cross-threading exception; our listview was created on the program's main thread and can't be changed
' directly by our background thread.

' To get round this little problem, we create delegate routines and then call the listview control's
' invoke method which uses the delegated routine to update the listview control on the main thread.

Private Delegate Sub AddItem(ByVal lv As ListView, ByVal lvi As ListViewItem)


Private Shared Sub AddListViewItem(ByVal listViewCtrl As ListView, ByVal lvi As ListViewItem)
           listViewCtrl.Items.Add(lvi)
       End Sub



listViewCtrl.Invoke(New AddItem(AddressOf AddListViewItem), New Object() {listViewCtrl, lvGroupItem})


Smile | :)
I'm too lazy to Google it for you.

GeneralRe: How to load 100,000 list view items without application freeze? Pin
Dave Kreskowiak1-Feb-11 12:23
mveDave Kreskowiak1-Feb-11 12:23 
AnswerRe: How to load 100,000 list view items without application freeze? PinPopular
Richard MacCutchan31-Jan-11 4:05
mveRichard MacCutchan31-Jan-11 4:05 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 6:43
professionalChesnokov Yuriy31-Jan-11 6:43 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Luc Pattyn31-Jan-11 4:13
sitebuilderLuc Pattyn31-Jan-11 4:13 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 6:49
professionalChesnokov Yuriy31-Jan-11 6:49 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Luc Pattyn31-Jan-11 6:57
sitebuilderLuc Pattyn31-Jan-11 6:57 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 7:03
professionalChesnokov Yuriy31-Jan-11 7:03 
QuestionRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 6:53
professionalChesnokov Yuriy31-Jan-11 6:53 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 6:55
professionalChesnokov Yuriy31-Jan-11 6:55 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Paw Jershauge31-Jan-11 9:00
Paw Jershauge31-Jan-11 9:00 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Richard MacCutchan31-Jan-11 9:15
mveRichard MacCutchan31-Jan-11 9:15 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Paw Jershauge31-Jan-11 12:18
Paw Jershauge31-Jan-11 12:18 
QuestionRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy1-Feb-11 1:14
professionalChesnokov Yuriy1-Feb-11 1:14 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Richard MacCutchan1-Feb-11 3:17
mveRichard MacCutchan1-Feb-11 3:17 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy31-Jan-11 10:00
professionalChesnokov Yuriy31-Jan-11 10:00 
GeneralRe: How to load 100,000 list view items without application freeze? Pin
Paw Jershauge31-Jan-11 12:17
Paw Jershauge31-Jan-11 12:17 
AnswerRe: How to load 100,000 list view items without application freeze? Pin
Chesnokov Yuriy1-Feb-11 1:10
professionalChesnokov Yuriy1-Feb-11 1:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.