Search code examples
c#wpfperformanceobservablecollectioninotifycollectionchanged

INotifyCollectionChanged -- How often does it fire (and how do they make it so efficient/fast)?


Basically, I'm wondering how it is actually efficient here.

Sample code:

void GetItems()
{
    foreach (var item in items)
        myObservableCollection.Add(item);
}

Won't this fire off the CollectionChanged event every time causing the UI to have to refresh everytime? Or does it do it so that it waits til the GetItems function is done?

Basically, it seems that WPF handles it very well, and I'm wondering how they did that.


Solution

  • The event will fire for every change.

    The GUI does not have to react and refresh every time, it can postpone that.
    I know WinForms will optimize this, I think WPF has a similar approach.