How to make ObservableCollection thread-safe?

前端 未结 4 849
天命终不由人
天命终不由人 2020-11-29 03:42
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

I am adding/removing from an ObservableCollection

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 04:04

    You can use a ObservableConcurrentCollection class. They are in a package provided by Microsoft in the Parallel Extensions Extras library.

    You can get it prebuilt by the community on Nuget: https://www.nuget.org/packages/ParallelExtensionsExtras/

    Or get it from Microsoft here:

    https://code.msdn.microsoft.com/ParExtSamples

提交回复
热议问题