Search code examples
c#multithreadingconcurrencyconcurrent-collections

Removing items from bottom of ConcurrentStack<T> or equivalent functionality


I've been searching for a while for an answer to my question, but I have not found a good solution to my problem. What I'm trying to do is basically have a concurrent collection that is sort of like a ConcurrentStack<T> but I need to be able to remove items from the bottom of the stack. This is because I wish to have the stack be only of a certain length, and thus any old items will get removed from the bottom when the collection gets too big.

The concurrent stack works great with the adding of objects, but removing them from the bottom is what I can't figure out.

I also had an idea of having a ConcurrentDictionary<TKey, TValue> where I keep track of the date added, and the object stored, and then remove items based on the last date.

Any help/ideas would be appreciated.


Solution

  • I think you need ConcurrentQueue Class