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
1 answer

Using yield with concurrent collection

This is a question coming off another discussion I had, however I was curious what would happen in the following situation when using a concurrent dictionary and the yield functionality. IEnumerable GetValuesNotZero() { foreach(int value in…
0
votes
0 answers

ConcurrentDictionary.Values return null?

There is a ConcurrentDirectory instance like below readonly ConcurrentDictionary _map = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); And there is a thread check…
Mr.Wang from Next Door
  • 13,670
  • 12
  • 64
  • 97
0
votes
1 answer

is this approach thread safe

Is approach below thread safe? I know ConcurrentDictionary provides TryRemove method but I just don't like to have a variable for value that I never gonna use. ConcurrentDictionary myDict = new ConcurrentDictionary(); if…
whoami
  • 1,689
  • 3
  • 22
  • 45
0
votes
1 answer

Updating the key object in AddOrUpdate method

I have a Test class. class Test { public int Id { get; set; } public int Val { get; set; } } I would like to setup a ConcurrentDictionary with an int as Key and Test as the value. bool External = true; ConcurrentDictionary data…
paul deter
  • 857
  • 2
  • 7
  • 20
0
votes
1 answer

How to work with OUT-value in ConcurrentDictionary.TryGetValue?

Help me pls to understand how does ConcurrentDictionary work? I have this: UsersOnlineClass client; if (UsersOnlineDictionary.TryGetValue(comClientID, out client)) { } I have to change some value in client and save changes in ConcurrentDictionary.…
0
votes
2 answers

Getting Duplicate Objects in Producer/Consumer ConcurrentDictionary C#

I'm stuck on a problem and am wondering if I just have coded something incorrectly. The application polls every few seconds and grabs every record from a table whose sole purpose is to signify what records to act upon. Please note I've left out the…
Arghanoah
  • 3
  • 2
0
votes
1 answer

what are the most efficient ways to use in-memory caching in C#

in a WCF app,i have 80k+ rows in database which rarely change. i want to cache them in memory for faster lookup. i should be able to evict them when needed. I have found some C# libraries for it. some of them use MemoryCache internally while others…
nur
  • 161
  • 2
  • 11
0
votes
0 answers

What is the simplest way to update a ConcurrentDictionary

I have created a ConcurrentDictionary but am unsure of how to update an element of it: public class ModelClient : ICloneable { public Session session; public List keys = new List(); …
ManInMoon
  • 6,795
  • 15
  • 70
  • 133
0
votes
1 answer

ConcurrentDictionnary tryAdd

When you are using ConcurrentDictionary and trying to add new key pairs to it using TryAdd it checks whether value exists and then add if not. Is there any way I can add duplicate keys wit different vales? Or maybe there is alternative thread-safe…
0
votes
1 answer

Nested ConcurrentDictionary

I want to create a nested ConcurrentDictionary after parsing a large XML file. What I get when running the code below is that the innermost(tmpDictionaryDid) dictionary is null. I guess I don't save the dictionaries properly or load them…
Fousk
  • 31
  • 4
0
votes
1 answer

using long (int64) as a hashCode and still use IEqualityComparer for concurrent Dictionary

I have a problem using a self made IEqualityComparer and GetHashCode in a concurrent dictionary. The class below (simplified with used two properties) works perfect when I implement it like this: ConcurrentDictionary
user369122
  • 792
  • 3
  • 13
  • 33
0
votes
2 answers

ConcCurrentDictionary Initialize

Is it possible to declare and initialize a ConcurrentDictionary? Maybe something like the Dictionary: Dim Stuff = New ConcurrentDictionary(Of Integer, Integer) From {{0, 1}, {2, 3}}
JoeB
  • 297
  • 4
  • 20
0
votes
2 answers

Do replace operations on different ConcurrentDictionary keys share one lock?

Does replacing a value associated with a ConcurrentDictionary key lock any dictionary operations beyond that key? EDIT: For example, I'd like to know if either thread will ever block the other, besides when the keys are first added, in the…
shannon
  • 8,664
  • 5
  • 44
  • 74
0
votes
0 answers

add Equality Comparer class to base class for custom property classes in c#

i'm using the ConcurrentDictionary were the key is made of a class with public properties. after playing around with the code from (HashCode on decimal with IEqualityComparer in a ConcurrentDictionary) I wanted to find a solution, so I don't have to…
0
votes
1 answer

Concurrent Dictionaries in C#

For a concurrent dictionary ConcurrentDictionary dic; (Where C is some class), does anyone know of a reference for the rules and restrictions for how one should perform operations on an instance of C, say C0, that is a value in the…
Chris W
  • 145
  • 1
  • 2
  • 12