concurrentdictionary Questions

2

Solved

I've got a caching class that uses cold (unstarted) tasks to avoid running the expensive thing multiple times. public class AsyncConcurrentDictionary<TKey, TValue> : System.Collections.Concu...

5

Solved

If I have a ConcurrentDictionary instance, does it matter whether I use the Count property or LINQ's Any()? I'd rather write dict.Any() instead of dict.Count > 0 as I think Any() is more descrip...
Bathypelagic asked 1/4, 2015 at 19:33

2

Solved

Is there a data structure similar to ConcurrentDictionary<TKey,TValue> and Interlocked.Exchange<T>(...) that would allow you atomically to set a new value and retrieve the old value ass...

3

Solved

I was wondering if I should use a List or Dictionary knowing that my structure would have very few items. So I did a simple benchmark 📊 to test for 1, 3, 10, 20 and 50 what was fastest data struct...
Joyous asked 21/12, 2023 at 15:7

5

Solved

I am trying to re-write some code using Dictionary to use ConcurrentDictionary. I have reviewed some examples but I am still having trouble implementing the AddOrUpdate function. This is the origin...
Altruism asked 11/8, 2011 at 15:49

2

I've run into an interesting issue. Knowing that the ConcurrentDictionary<TKey, TValue> is safely enumerable while being modified, with the (in my case) unwanted side-effect of iterating over...
Quadripartite asked 8/12, 2016 at 11:35

2

Solved

I'm using a concurrent dictionary to store about two million records and want to know what to initialize the concurrency level of my dictionary to. The MSDN page has the following comment in its ex...
Famagusta asked 7/5, 2015 at 21:30

6

Solved

Does a cast from ConcurrentDictionary to IDictionary cut off the thread-safe implementation, since IDictionary doesn't have GetOrAdd and AddOrUpdate methods ?
Keelykeen asked 11/4, 2012 at 18:55

1

Solved

I tried BlockingCollection and ConcurrentDictionary. It continues by adding BlockingCollection items as soon as the thread is completed, but ConcurrentDictionary is always adding thread order. Is t...
Philippeville asked 24/1, 2023 at 20:19

5

I have a scenario where I have to keep reference counted object for given key in the ConcurrentDictionary, if reference count reaches 0, I want to delete the key. This has to be thread safe hence I...

2

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 parallel...
Wherever asked 3/7, 2022 at 13:51

6

Solved

I have a ConcurrentDictionary object that I would like to set to a Dictionary object. Casting between them is not allowed. So how do I do it?
Jackjackadandy asked 2/12, 2010 at 0:58

9

Solved

Related brief info: AFAIK , The concurrent stack, queue, and bag classes are implemented internally with linked lists. And I know that there is much less contention because each thread is respons...

3

I try to implement a ConcurrentDictionary by wrapping it in a BlockingCollection but did not seem to be successful. I understand that one variable declarations work with BlockingCollection such as ...

6

Solved

I am after a collection with the following properties: Thread safe: It will be used in asp.net and multiple clients could try to add, remove and access members concurrently Max elements: I want to...
Culbertson asked 10/12, 2014 at 14:29

5

I want to use something like GetOrAdd with a ConcurrentDictionary as a cache to a webservice. Is there an async version of this dictionary? GetOrAdd will be making a web request using HttpClient, s...
Subtraction asked 9/1, 2019 at 20:16

5

Solved

I'm always confused on which one of these to pick. As I see it I use Dictionary over List if I want two data types as a Key and Value so I can easily find a value by its key but I am always confuse...
Mcintosh asked 2/2, 2017 at 22:8

3

Solved

I am performing two updates on a value I get from TryGet I would like to know that which of these is better? Option 1: Locking only out value? if (HubMemory.AppUsers.TryGetValue(ConID, out OnlineIn...
Brassica asked 5/3, 2021 at 8:14

2

The app needs to load data and cache it for a period of time. I would expect that if multiple parts of the app want to access the same cache key at the same time, the cache should be smart enough t...
Schmaltzy asked 9/1, 2021 at 8:15

1

Solved

TL;DR: Is it possible for a single enumeration of a ConcurrentDictionary, to emit the same key twice? Does the current implementation of the ConcurrentDictionary class (.NET 5) allow this possibili...
Merrow asked 22/12, 2020 at 23:7

3

ConcurrentDictionary.GetOrAdd(TKey, Func<TKey, TValue>) accepts a factory function to allow lazy instantiation of the item to be put into the dictionary. Is it safe to define a factory funct...
Wholesome asked 14/11, 2016 at 13:33

2

Solved

As per this solution (https://mcmap.net/q/118417/-concurrent-hashset-lt-t-gt-in-net-framework) I am using a ConcurrentDictionary<T,byte> as a workaround for the lack of ConcurrentHashSet<T...
Shrub asked 7/4, 2020 at 17:2

2

ConcurrentDictionary.TryUpdate method requires the comparisonValue that is compared with the value of the element that has the specified key. But if I trying to do something like this: if (!_store...
Lueck asked 10/10, 2018 at 16:58

1

Solved

In the .NET Framework, there is Dictionary and ConcurrentDictionary. These provide method like Add, Remove, and so on... I know when we design a multi-thread program, we use ConcurrentDictionary t...
Belshin asked 23/8, 2019 at 7:11

2

Solved

If I have the following code: var dictionary = new ConcurrentDictionary<int, HashSet<string>>(); foreach (var user in users) { if (!dictionary.ContainsKey(user.GroupId)) { dictiona...
Aquatic asked 20/11, 2018 at 0:16

© 2022 - 2024 — McMap. All rights reserved.