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

Sorting ConcurrentDictionary makes any sense?

At first my thought was like "this is an hash-based data type, then it is unsorted". Then since I was about to use it I examined the matter in depth and found out that this class implements IEnumerable and also this post confirmed that it is…
Leggy7
  • 483
  • 9
  • 23
2
votes
2 answers

passing concurrentdictionary to another method

I'm facing some problem in passing ConcurrentDictionary to another method with an out parameter. In main method, Method1(1,2,dictionary); public override int Method1(int x,int y, out ConcurrentDictionary dictionary) { …
taesica
  • 35
  • 2
  • 6
2
votes
2 answers

Is ConcurrentDictionary, a "concurrent" version of SortedList?

I would like to understand the Computational Complexity of a ConcurrentDictionary vers SortedList (Which is O(logarithmic(n))), is a ConcurrentDictionary just a concurrent synchronized implementation of a SortedList? or do these data structures…
classicjonesynz
  • 4,012
  • 5
  • 38
  • 78
2
votes
1 answer

Is there anything like a ConcurrentSet in .Net?

I've used the ConcurrentDictionary in .Net and fell in love with how easy it is to write concurrent classes using it. Now, I have a different scenario though. I basically need to keep track of a single object type in an non-duplicated unordered…
Earlz
  • 62,085
  • 98
  • 303
  • 499
2
votes
2 answers

C# Concurrent Dictionary not saving my List value between page loads

It's been a while since I've been this stumped. The crazy thing is, I've done this several times in other areas of my code, so it's almost complete copy and paste, but except this code isn't working properly. so I am somehow missing something…
ijjo
  • 525
  • 9
  • 22
1
vote
2 answers

Incrementing a integer value in a concurrent dictionary

I have a concurrent dictionary which is a class variable: private readonly ConcurrentDictionary _tracker= new ConcurrentDictionary(Id.EqualityComparer); I'm incrementing it in a method as follows: _tracker[id]++; Is…
Riyafa Abdul Hameed
  • 7,417
  • 6
  • 40
  • 55
1
vote
1 answer

The dictionary cannot map the key

I have a concurrent dictionary which maps an array of characters to an integer var dictionary = new ConcurrentDictionary(); It works fine if I map an array var key = new char[] { 'A', 'B' }; var value = 8; dictionary.TryAdd(key,…
Fenix FVE
  • 53
  • 4
1
vote
2 answers

What thread-safe collection use to cache messages

I'm working on project with following workflow : Background service consumme messages from Rabbitmq's queue Background service use background task queue like this and here to process task paralleling Each task execute queries to retrieve some datas…
1
vote
1 answer

ConcurrentQueue in a ConcurrentDictionary Duplicate Error

I have a thread that handles the message receiving every 10 seconds and have another one write these messages to the database every minute. Each message has a different sender which is named serialNumber in my case. Therefore, I created a…
Taylan Yuksel
  • 345
  • 3
  • 12
1
vote
3 answers

Are nested Dictionaries thread safe from parent ConcurrentDictionary?

If I have a ConcurrentDictionary object ConcurrentDictionary>() dict;, is the nested Dictionary locked when operations are being performed on the outer ConcurrentDictionary? Scenario: an outer ConcurrentDictionary…
jixox
  • 13
  • 2
1
vote
1 answer

Adding a listener event to a ConcurrentQueue or ConcurrentBag?

I have multiple tasks that grab messages from a queue in a 1:1 fashion. I want to add these messages from each thread into a ConcurrentBag and process them as they come in asynchronously. The purpose here is to get messages off the queues as quickly…
1
vote
1 answer

Avoid closure in ConcurentDictionary

I have current function public static ICacheManager GetCacheManager(string cacheManagerName, TimeSpan? expiration) { var cacheManager = CacheManagers.GetOrAdd(cacheManagerName, keyName => { var…
Raptor
  • 392
  • 1
  • 4
  • 21
1
vote
1 answer

.NET locking or ConcurrentDictionary?

I'm writing something like a file cache and I'm debating between using lock or ConcurrentDictionary. If multiple threads ask for a key, then an ordinary Dictionary will have issues if two threads try to write to it, so I tried ConcurrentDictionary.…
imekon
  • 1,501
  • 4
  • 22
  • 39
1
vote
2 answers

Is there a way to lock a concurrent dictionary from being used

I have this static class static class LocationMemoryCache { public static readonly ConcurrentDictionary LocationCities = new(); } My process Api starts and initializes an empty dictionary A background job starts and…
1
vote
1 answer

Make a snapshot and empty a ConcurrentDictionary

I have a ConcurrentDictionary that I want to empty, copying its content into a dictionary (or any other container) while emptying it at the same time. A key invariant is that no element from the source is lost during the operation. My current code…
mookid
  • 1,132
  • 11
  • 19