Replacement for ObservableCollection?

2020-07-23 04:56发布

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?

3条回答
狗以群分
2楼-- · 2020-07-23 05:07

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楼-- · 2020-07-23 05:08

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

查看更多
Animai°情兽
4楼-- · 2020-07-23 05:09

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.

查看更多
登录 后发表回答