Questions tagged [concurrent-collections]

Concurrent Collections are several collection implementations in .Net that support multi-threaded access in a safe and efficient way

Concurrent Collections are several collection implementations in .Net that support multi-threaded access in a safe and efficient way. Some of those collections are ConcurrentQueue, ConcurrentStack, ConcurrentBag.

References

98 questions
3
votes
2 answers

IProducerConsumerCollection.TryAdd/.TryTake - when do they return true/false?

When I call IProducerConsumerCollection.TryAdd() or IProducerConsumerCollection.TryTake(out ) will these ever fail because another thread is using the collection? Or is it the case that if there is space to Add or something to Take even…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
2
votes
2 answers

WPF UI is not updating on change of ConcurrentBag type collection

I have collection which is bounded to datagrid in WPF UI. My requirement is like i have to update the the value of a property 10 times a second for every item in collection. So i have taken ConcurrentBag type collection. After updating the value for…
D J
  • 6,908
  • 13
  • 43
  • 75
2
votes
1 answer

Collecting results of async within lambda

I have these example code: private async Task> GetValidIds1(long[] ids) { var validIds = new List(); var results = await Task.WhenAll(ids.Select(i => CheckValidIdAsync(i))) …
2
votes
1 answer

While adding element into ArrayList using Multithreading, sometimes it give ConcurrentModificationException and sometimes not?

I tried iterating ArrayList object using multi-threading, but sometimes it is giving ConcurrentModificationException and sometimes not? I am unable to understand what is happening here. I am sharing my code below: import java.util.ArrayList; import…
2
votes
4 answers

How to speed up routines making use of collections in multithreading scenario

I've an application that makes use of parallelization for processing data. The main program is in C#, while one of the routine for analyzing data is on an external C++ dll. This library scans data and calls a callback everytime a certain signal is…
Mauro Ganswer
  • 1,379
  • 1
  • 19
  • 33
2
votes
3 answers

Batch process all items in ConcurrentBag

I have the following use case. Multiple threads are creating data points which are collected in a ConcurrentBag. Every x ms a single consumer thread looks at the data points that came in since the last time and processes them (e.g. count them +…
2
votes
2 answers

Another ConcurrentModificationException question

I've searched StackOverflow and there are many ConcurrentModificationException questions. After reading them, I'm still confused. I'm getting a lot of these exceptions. I'm using a "Registry" setup to keep track of Objects: public class Registry { …
2
votes
7 answers

Are there good IList and IDictionary implementations in C# that support fail-safe iteration?

Per the title - are there good built-in options in C#/.NET for fail-safe iteration over an IList or an IDictionary? Where I'm running into problems is with code similar to the following: IList someList = new List(); //... foreach (Foo…
Sbodd
  • 11,279
  • 6
  • 41
  • 42
2
votes
3 answers

.Net 4.0 Parallel Programming - how to write data to concurrent collections?

I have a grid which is defined as: List>, where "Cell" is a custom class of mine. My program has several threads which access various coordinates on the grid, and change data in the "Cell" class. But I only want one thread writing data to…
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
2 answers

Concurrent Collections and Linq

Is Concurrent Collections are thread safe when we use them in linq queries? and what is the difference between Concurrent Collection and Immutable Collections??
2
votes
2 answers

Adding to concurrent collections

When working with a concurrent collection (for example ConcurrentDictionary) should I use TryAdd method, or just a plain old index assignment? I mean, do TryAdd method blocks when adding, so if another thread would try to remove the value it would…
Marek M.
  • 3,799
  • 9
  • 43
  • 93
2
votes
1 answer

Slow interation over a ReadWriteLock protected map: read lock, concurrent map or copying?

I have a map that is frequently read but rarely write to. Some operations (can be reading or writing) involves multiple objects that needs to be operated atomically, so I used a ReadWriteLock to improve performance. Now I have the option to…
billc.cn
  • 7,187
  • 3
  • 39
  • 79
2
votes
1 answer

How do I measure the FLOPS my C# app uses?

Microsoft's Parallel Programming whitepaper describes situations that are optimal under various FLOPS thresholds, and that the FLOPS rate is a decision point as to when a certain implementation should be used. How do I measure FLOPS in my…
1
vote
3 answers

Why isn't there a ConcurrentList

The new namespace System.Collections.Concurrent contains concurrent collections for dictionary, queue and stack among other classes. Anyone know why is it that there is no ConcurrentList? UPDATE I've posted a new question explaining my current…