I cannot seem to find a .NET thread safe / concurrent collect that supports a simple Remove() function where I can either remove a specific item or pass in a predicate to remove items based on that. I have tried:
BlockingCollection<T>
ConcurrentQueue<T>
ConcurrentStack<T>
ConcurrentBag<T>
Does anyone know of a collection that supports this behavior, or do I have to create my own?
I want to be able to grab the next item from a thread-safe queue without removing it, and later on if a certain condition is met, proceed with removing it.
Have you tried ConcurrentDictionary
? It has a TryRemove
method, so if you think of the key as a predicate, then you will be removing the correct item.
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