Questions tagged [concurrentdictionary]

ConcurrentDictionary is a .Net thread-safe collection of key-value pairs that can be accessed by multiple threads at the same time.

ConcurrentDictionary is a .Net thread-safe collection of key-value pairs that can be accessed by multiple threads at the same time.

References

331 questions
-1
votes
1 answer

ConcurrentDictionary and threads

I have a WCF service in IIS App pool. Method of WCF service receives some data in JSON, like {"object": "someobject", "payload": [int key]}. For each request I running new thread to work with key. Key is adding to ConcurrentDictionary and locks…
-1
votes
1 answer

Why ConcurrentDictionary.tryAdd modify the order of item in the dictionnary ? c#

I add four elements in a Dictionary, and iterate trough the dictionary with a ForEach loop : items are in the order of adding. I add four elements in a ConcurentDictionary, and iterate trough the ConcurentDictionnary with a ForEach loop : items are…
Artibrico
  • 13
  • 3
-1
votes
1 answer

Adding Parallel.Foreach results do a dictionary when iteration completes

I've read a few links here but i couldn't come up with an answers to my question. What i'm trying to achieve is to add the results of the Parallel.ForEach into a ConcurrentDictionary. However, how can i be sure that i'm adding the result of the…
-1
votes
3 answers

Dictionary vs Concurrent Dictionary

I am trying to understand when to use Dictionary vs ConcurrentDictionary because of an issue I had with one of the changes I made to a Dictionary. I had this Dictionary private static Dictionary _strategySides = null; In the…
challengeAccepted
  • 7,106
  • 20
  • 74
  • 105
-1
votes
1 answer

Will this C# code work in thread-safe mode?

I need to be able to get the Project by ID and safely change the properties of it. I am not the specialist in multi-threading. So, please, help me with this. public static class Application { private static ConcurrentDictionary
-1
votes
1 answer

Concurrent Dictionary safety usage

I need to thread-safe way to get each item of the ConcurrentDictionary(string, List) Does it safety to use the following construction? foreach (var item in concurrentDict) { var readonlyCollection = item.Value.AsReadOnly(); //use readonly…
-1
votes
1 answer

Is it safe to pass ConcurrentDictionary type into a function that takes IDictionary?

I have a method: void foo(IDictionary data) { data["key1"] = getValue1(); data["key2"] = getValue2(); } I currently call it as follows: var serialDict = new Dictionary(); foo(serialDict); Now I need to call…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
-1
votes
1 answer

Locks on ConcurrentDictionary values' properties

Imagine a ConcurrentDictionary storing a collection of Foo. Is it necessary to worry about thread safety for the Bar property of Foo (e.g. thread 1 getting value of Bar at same time thread 2 setting the value)? Or does the concurrency of the…
philorube
  • 155
  • 8
-1
votes
2 answers

updating Dictionary code with ConcurrentDictionary

How to update the following code to use a ConcurrentDictionary? private Dictionary (string, SymbolOrderBook) books = new Dictionary(string, SymbolOrderBook)(); SymbolOrderBook book; lock (books) { if (!books.TryGetValue(symbol, out book)) …
-1
votes
1 answer

Retrieve collection of elements whose key is less than specified value in c#

I have a dictionary which isConcurrentDictionary mensajesEnviados = new ConcurrentDictionary(); I want to retrieve all the objects Mensaje whose key value is less than a certain value, to iterate on them. How should I…
asCii88
  • 23
  • 6
-1
votes
1 answer

ConcurrentDictionary AddOrUpdate with function

I have a ConcurrentDictionary: Node n = new Node() { Id = 1, Title = "New title" }; this.nodes.AddOrUpdate((int)n.Id, n, (key, existingVal) => { existingVal.Update(n); return existingVal; }); My Node class implements…
Asken
  • 7,679
  • 10
  • 45
  • 77
-2
votes
2 answers

Can I simplify my ConcurrentDictionary "add or update" method?

I have code like this: public ConcurrentDictionary deviceStatesCache = new ConcurrentDictionary(); private readonly object deviceStatesCacheLock = new object(); public void StoreDeviceStateInCache(Guid guid,…
Kamil
  • 13,363
  • 24
  • 88
  • 183
-2
votes
3 answers

AddOrUpdate method of ConcurrentDictionary always do lock (not skip if values equals)

I read code of AddOrUpdate method in Reference Source and saw that if oldValue and newValue are equaled the method will do the update anyway. Is it true? Did i understand it correct? Because of it the method always do lock. update: When i saw the…
-2
votes
1 answer

Multiple threads are accessing and modifying different elements at a time in concurrent dictionary

I am using a ConcurrentDictionary> in a multi threaded environment. Multiple threads are accessing the same dictionary for retrieving and modifying the item with unique key only. I mean although there are multiple threads…
-3
votes
1 answer

ConcurrentDictionary AddOrUpdate method throwing IndexOutOfRangeException

Jobs are getting added to the HashSet by different threads and throwing this error. Is there any solution for this ? ConcurrentDictionary> _dictKeyJob; _dictKeyJob.AddOrUpdate(myKey, key => { return new HashSet({ Job…
rajibdotnet
  • 1,498
  • 2
  • 17
  • 29
1 2 3
22
23