0

Is it possible to update a large ObservableCollection (i.e. add items) without hanging to U.I.?

I'm wondering if it's the fact that I have a relatively large loop (500 iterations) where each iteration is adding an item to the collection.

OR, whether it is the fact that the collection is being refreshed and notifying the UI of a change.

OR... both!

I did come across this thread, but that might be a different question altogether regarding the Dispatcher (why would using the dispatcher help?): Using BackgroundWorker to update the UI without freezes...?

Community
  • 1
  • 1
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140

1 Answers1

1

Check this previous SO answer.

ObservableCollection doesn't allow you to disable and re-enable the events that are fired for changes but it seems you can with BindingList.

Community
  • 1
  • 1
Erik Noren
  • 4,279
  • 1
  • 23
  • 29
  • Cool. I hope SL has binding lists. I'll definitely go this route if i can. But, for now, i'd like to know if updating a collection on an async completed event via the Dispatcher would help alleviate the UI 'freezes'. can anybody confirm or deny this? – AlvinfromDiaspar Nov 01 '10 at 19:15
  • Using the dispatcher won't help. All that does is marshal cross-thread access for you. (For instance if you want to update some UI from a different thread, you use the Dispatcher to invoke the UI commands.) Your collection is still going to raise events each time the collection is modified and any listeners will be notified. Since they are subscribing to the events using multicast delegates, their notices come in on new threads and thus they aren't blocked or blocking from your observable collection updates. Can you make your updates to an IEnumerable then make ObservableCollection? – Erik Noren Nov 01 '10 at 22:52