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
2
votes
3 answers

Concurrent collection containing regular collection .net

Let's say I have ConcurrentDictionary> sampleCollection;. Is it thread safe to perform operations on sampleCollection[1] (which is a HashSet)? In general, if we have a not thread-safe collection inside a thread-safe…
2
votes
1 answer

Ordering a ConcurrentDictionary. Why is this not working?

We have a C# app that populates tables on worksheets within an Excel document. The tables must be populated in the order the rows are returned from the database. The object DataFileColData is defined as a List and contains the result set rows. For…
2
votes
1 answer

valueFactory in Concurrent dictionary

I am writing a winform program to test the C# concurrent dictionary with below class: public class Class1 { public int X = 10; public Class1(int x) { X = x; Debug.WriteLine("Class1 Created"); } } and below button…
Sean
  • 981
  • 1
  • 9
  • 19
2
votes
0 answers

ConcurrentDictionary TryUpdate equality comparer

I have a ConcurrentDictionary that I use as a hash table that will refresh at a regular time interval. the TValue of my ConcurrentDictionary is a custom class that I created : public class RefreshableDictionaryValue { private DateTime…
Adrian Buzea
  • 826
  • 2
  • 11
  • 33
2
votes
3 answers

Concurrent Collection with fastest possible Add, Remove and Find the highest

I am doing some heavy computations in C# .NET and when doing these computations in parallel.for loop I must collect some data in collection, but because of limited memory I can't collect all results, so I only store the best ones. Those computations…
2
votes
2 answers

Is it safe to r/w dictionary entries in a Parallel.ForEach in c#

I have a dictionary which I would like to modify it's values in a foreach loop, however, since my application is time critical, I'm trying to avoid all unnecessary locking overheads. var loopData = new Dictionary>(); var results =…
2
votes
1 answer

ConcurrentDictionary - AddOrUpdate issue

I'm using this code below to try to update the values in a dictionary object depending on its key. public static ConcurrentDictionary UsersViewModel = new ConcurrentDictionary
user3228992
  • 1,373
  • 1
  • 16
  • 31
2
votes
2 answers

Using ConcurrentDictionary as a cache and handling update

I have the below code and now I want to add an UpdateSetting method. The best way of doing this that I can see is via TryUpdate on the ConcurrentDictionary but that means knowing the previous value so that would require a call to GetSetting which…
Jon
  • 38,814
  • 81
  • 233
  • 382
2
votes
1 answer

ConcurrentDictionary adding same keys more than once

I want to use ConcurrentDictionary to check if this data key has been added before, but it looks like I can still add keys which added before. code: public class pKeys { public pKeys() { } public pKeys(long sID, long…
2
votes
2 answers

iterating through ConcurrentDictionary and modifying the collection

What is the correct way to iterate through ConcurrentDictionary collection and deleting some entries. As I understand ConcurrentDictionary implements locking on a level of a cell, and for me is important to iterate through whole collection and…
Night Walker
  • 20,638
  • 52
  • 151
  • 228
2
votes
3 answers

Thread-safe changes to a ConcurrentDictionary

I am populating a ConcurrentDictionary in a Parallel.ForEach loop: var result = new ConcurrentDictionary(); Parallel.ForEach(allRoutes, route => { // Some heavy operations lock(result) { if…
2
votes
1 answer

Is it possible to serialize an array of ConcurrentDictionary using protobuf-net?

Is it possible to serialize the following class using protobuf-net? I have looked all over and I cannot find any examples for such a scenario? [ProtoContract] public class Example { [ProtoMember(1)] public ConcurrentDictionary
Jake Drew
  • 2,230
  • 23
  • 29
2
votes
3 answers

Implementing a generic ToConcurrentDictionary extension method

I Was trying to add some type safe dictionary logic to my app and tried to look around for an implementation to convert a given dictionary to a concurrent one. After searching for a while with no luck, I ended up implementing a version of my own…
siva
  • 169
  • 1
  • 1
  • 12
2
votes
1 answer

Update in one Concurrentdictionary is reflected in main dictionary

I have two concurrent dictionaries say var MainDic = new ConcurrentDictionary(); and var TempDic = new ConcurrentDictionary(MainDic); My TempDic contains same data as MainDic.I do computations on TempDic. whatever…
Nikita P
  • 41
  • 4
2
votes
1 answer

ConcurrentDictionary on large numbers

I wonder to know why ConcurrentDictionary getOrAdd method slows down heavily as entry number grows up. I call it inside 3 nested loops and, printing to file the time of each innest loop, I can see that the execution time of each innest loop grows…
Leggy7
  • 483
  • 9
  • 23