Replacement for ObservableCollection?

。_饼干妹妹 提交于 2019-12-09 19:19:21

问题


I'm looking for a replacement for ObservableCollection that is thread-safe, raises events on the UI thread and preferably has an AddRange method. I've seen a few implementations posted here and elsewhere, but I'd prefer an implementation that has been tested and validated and that I won't have to maintain myself.

So can anyone point me to such a replacement, preferable available via NuGet?


回答1:


For thread safe collections check the System.Collections.Concurrent namespace. ConcurrentStack has a PushRange method that inserts multiple objects at the top of the stack.




回答2:


You could try using the BulkObservableCollection from Microsoft, although I'm not sure why they put it in such a strange namespace! Didn't see it listed when I tried to "Add reference..." in VS2012, had to manually browse to C:\Windows\Microsoft.NET\assembly\GAC_MSIL




回答3:


You can try the one described here:

http://deanchalk.com/2010/02/01/thread-safe-dispatcher-safe-observable-collection-for-wpf/

It is a full implementation in a blog post. It is available as source (from that page), so it might not meet your tested/validated criteria.

I have not used it, so I cannot vouch for how well it works (or doesn't).

UPDATE: The old link was broken. I replaced it with the current link. The Dean Chalk is actually a member here on SO, so here is a link to his SO profile in case it ever breaks again:

https://stackoverflow.com/users/328848/dean-chalk



来源:https://stackoverflow.com/questions/12467337/replacement-for-observablecollection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!