Why isn't it possible to update an ObservableCollection from a different thread?

后端 未结 2 1776
忘了有多久
忘了有多久 2020-12-29 00:21

In a multi-threaded WPF application, it is not possible to update an ObservableCollection from a thread other than WPF window thread.

I know there are w

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 00:59

    If your collection is bound to user interface elements, those user interface elements are listening on the CollectionChanged event of the collection, and this event is raised on the thread, on which you are updating the collection.

    So the problem is with the user interface elements, which can only be accessed from the thread, on which they were created, and not with the collection itself.

提交回复
热议问题