Is there a c# equivalent of Java ConcurrentHashMap
I need a dictionary/hashmap in c# that allow you to do the following
- put values and iterate at the same time without a lock
- lock only put. get are no开发者_如何转开发t locked and you may get many times concurrently
Thanks
Have a look at the ConcurrentDictionary here: http://msdn.microsoft.com/en-us/library/dd287191.aspx. This should do what you're looking for. Keep in mind, it's .Net 4 only.
check out the System.Collections.Concurrent - Namespace! http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx
That sounds like ConcurrentDictionary<TKey, TValue>
to me, available in .NET 4.0 or .NET 3.5 if you've installed Reactive Extensions.
You could also write your own class by using the ReaderWriterLockSlim Class
.
Otherwise simply take a look into the System.Collections.Concurrent Namespace
.
精彩评论