Wednesday 17 October 2012

To Update an ObservableCollection on a Background Thread or Not To?

ADD, REMOVE, REPLACE - NO
MODIFY - YES

Modifying an ObservableCollection will lead to an event being raised, which is handled on the same thread as the modification. If you add or remove items from an ObservableCollection from a background thread, the event gets raised before the Add/Remove gets completed.

If you are just changing properties in the elements (trivial updates) you should be fine. The processing can happen in the background, and the trivial update can happen on the main thread, no problems. GUI response time should not be impacted.

No comments: