I need a container where insert is fast and thread-safe, because I plan to use it inside a Parallel.for_each instance.
Once in a while, I will scan said container and remove every items contained.
What's the best choice given those costraints?
Thanks
You could use a ConcurrentBag<T>. Basically the System.Collections.Concurrent namespace is worth checking. If you have unique keys, a ConcurrentDictionary<TKey, TValue> would be a great choice as it provides you a very fast access to elements given a key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With