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
0
votes
0 answers

Parallel Program takes too much time

This is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Collections.Concurrent; namespace ConsoleApplication2 { public class c_Thread { public bool…
Adhil
  • 1,678
  • 3
  • 20
  • 31
0
votes
2 answers

Parallel.ForEach return order by input not by execution into list/dictionary

If you have this: var resultlist = new List>(); Parallel.ForEach(input, item => { resultlist.Add(SomeDataDictionary(item)); }); The return data will be in the order in which the method SomeDataDictionary returns the…
nik
  • 1,672
  • 2
  • 17
  • 36
0
votes
3 answers

How to add the items in ConcurrentDictionary>

I have a concurrentdictionary of > lets say object as Artifact. I wanted to add a new object. The object usually contains list of keys and I have a function to get those keys. I know how to add to the dictionary if the key doesn't exist but I am not…
Chit Khine
  • 830
  • 1
  • 13
  • 34
0
votes
1 answer

Iterating through ConcurrentDictionary values by key

I have a ConcurrentDictionary that I am adding elements to. The key is not unique, and may reflect multiple values. I iterate through the keys to get the unique names of them I iterate through the values by key to get a list of the values The…
user4914655
0
votes
1 answer

Why can I not add null as a value when using ConcurrentDictionary?

Consider the following code: // holds the actual values private volatile ConcurrentDictionary values; public object this[string key] { get { // exception is thrown on this line …
dmarra
  • 853
  • 8
  • 23
0
votes
2 answers

Why is the value returned from a ConcurrentDictionary always null when multiple concurrent threads are used?

I've implemented a simple memory cache backed by the ConcurrentDictionary public class MemoryCache { private ConcurrentDictionary _memory; public MemoryCache() { this._memory = new…
Stephen Patten
  • 6,333
  • 10
  • 50
  • 84
0
votes
1 answer

C# thread safely "refreshing" contents of a concurrentdictionary

I'm updating the dictionary using a method which takes in a list. This list contains what should be the updated values stored in the dictionary. For example: I have the values 1,2,3,4 stored in my dictionary. A thread attempts to update the values…
0
votes
1 answer

Threads and Their interaction with a Concurrent Dictionary and sw.Flush();

Consider this code: class program { public static ConcurrentDictionary dictionary = new ConcurrentDictionary(); static void Main(string[] args) { runServer(); } static void runServer() { …
James
  • 356
  • 2
  • 13
0
votes
2 answers

AddOrUpdate not updating

I have a concurrent dictionary _dict of type I loop through the items of another list of strings (list1), and if the item exists as a key in _dict, I increment its value; if it doesn't, I add it to _dict and set its value to…
IsaacBok
  • 424
  • 5
  • 18
0
votes
0 answers

ConcurrentDictionary with "expensive" value

I have a multi-threaded application that implements async methods. The application communicates over RabbitMq and at times needs to do a costly operation (BasicConsume on an IModel). I have a ConcurrentDictionary where I keep IModel (key) and it's…
0
votes
1 answer

How is this cache manager storing the cached data?

I am using this cache manager, taken from bbarry on github. I don't understand where or how the cached data is actually being stored. Most caching I've seen uses MemoryCache, but I don't see a mention of this anywhere. I can only think that the…
Martin Hansen Lennox
  • 2,837
  • 2
  • 23
  • 64
0
votes
1 answer

ConcurrentDictionary in WCF chat service, can add but not remove

So I have created a chat service using WCF and so far everything works as it should. The only issue I have is when the user logouts out. I am using a ConcurrentDictionary to hold all the connected clients and when use TryRemove it always returns…
Gaz83
  • 2,293
  • 4
  • 32
  • 57
0
votes
2 answers

locking multiple objects: scenarios and risks

I want to load some objects from database and cache them. It's simple: public class Dal { public Entity GetEntity(int id) { var cacheKey = string.Format(".cache.key.{0}", id); var item = Cache.Get(cacheKey) as Entity; …
amiry jd
  • 27,021
  • 30
  • 116
  • 215
0
votes
1 answer

Do I need a lock in AddOrUpdate of a concurrent dictionary?

in my class I have public static ConcurrentDictionary> ConnectedUserConnections = new ConcurrentDictionary>(); When adding or updating, should I update…
Fred Johnson
  • 2,539
  • 3
  • 26
  • 52
0
votes
0 answers

Thread-safe way to check ConcurrentDictionary while adding to it?

In my program, i'm iterating through a list of 'Group' objects using a Parallel.Foreach loop. Inside this loop, I first check my concurrentdictionary if a key exists, and if the value contains a Group property. I then add an object to a list…
Steve
  • 571
  • 8
  • 16