2

I am creating a WPF application that displays thousands of records in the datagrid. I'm loading the data coming from external source asynchronously in ObservableCollection and binding it to the datagrid. There will be several addition and updates to the grid all day long.

Performance wise is ObservableCollection suitable for this kind of application or should I look for ObservableDictionary or any other suitable collection?

Learner
  • 980
  • 7
  • 20
  • 37

3 Answers3

0

I've used it for real-time display of up to 10,000 records without any problems. Once you start manipulating that many records the bottlenecks tend to be algorithm selection and problems with data virtualization (or lack thereof) rather than which collection class you use. That said, if you're worried about it then there's an article here with a WPF-decoupled ObservableCollection that you could try using instead.

Mark Feldman
  • 15,731
  • 3
  • 31
  • 58
  • The article is totally outdated already, as `ObservableCollection` has been removed from WindowBase and totally decoupled from WPF itself since .NET 4.0. – Alejandro Jan 26 '14 at 23:03
0

DataGrid usses UI virtualization in order to paint only whats visible on the view port area. This reduces the number of UI elements which created and therefor makes it better in memory and performance. However, When you are dealing with ObservableCollections which contains thousands of Items you should consider using also Data virtualization techniques.

I would recommend to go KIS (Keep It Simple) and go ahead and try the simplest approch: Just use the .NET ObservableCollection.

If you are experinced laggy UI during updates you need to consider trying some kind of ObservableCollection which allows blocking UI updates during update phase (In case you need to update the collection in lots of items in short time).

If you are experince laggy UI during scrolling or selcting, or your memory is too high, you need to consider Data virtualization also.

Good luck

Moran Moshe
  • 114
  • 1
0

ObservableCollection notifies View for every item that is added to it, and it does not support AddRange() method. I would recommend and extended class for ObservableCollection that supports AddRange() Method posted in this Answer

This Class get updated for the entire bulk. Instead of each Item. Rest of performance will be responsibility of DataGrid which by default supports Virtual StackPanel

Community
  • 1
  • 1
Mujahid Daud Khan
  • 1,983
  • 1
  • 14
  • 23