3

I am looking for a way to :

  1. read messages from a ConcurrentQueue limited to some size.
  2. read not more then X message at a time frame. I want to stop the reading from Q once one of the 2 hit, until other code is done and do the same thing again.

I saw different implementation for Queue spill over, in here Fixed size queue which automatically dequeues old values upon new enqueues but can't figure out how to combine them correctly.

public class FixedSizedQueue<T>
{

    public int Size { get; private set; }

    public FixedSizedQueue(int size)
    {
        Size = size;
    }

    public void Enqueue(T obj)
    {
        queue.Enqueue(obj);

        while (queue.Count > Size)
        {
            T outObj;
            queue.TryDequeue(out outObj);
        }
    }
}
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
developer learn999
  • 365
  • 1
  • 4
  • 17

0 Answers0