开发者

Is there a c# equivalent of Java ConcurrentHashMap

开发者 https://www.devze.com 2023-02-15 20:14 出处:网络
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

I need a dictionary/hashmap in c# that allow you to do the following

  1. put values and iterate at the same time without a lock
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消