A thread-safe collection type for a fixed length of elements, overwriting the oldest element
$ dotnet add package Soenneker.Utils.ConcurrentCircularQueue
Soenneker.Utils.ConcurrentCircularQueuedotnet add package Soenneker.Utils.ConcurrentCircularQueue
Instantiate a ConcurrentCircularQueue<T> object by specifying the maximum size of the queue.
var myQueue = new ConcurrentCircularQueue<int>(3); // Creates a queue with a maximum size of 3.
Add an item to the queue. If the queue has reached its maximum size, the oldest item will be removed.
myQueue.Enqueue(1);
myQueue.Enqueue(2);
myQueue.Enqueue(3);
myQueue.Enqueue(4);
// The queue now contains 2, 3, and 4.Remove and return the oldest item from the queue.
bool success = myQueue.TryDequeue(out var item);Determine if a specific item is in the queue.
bool exists = myQueue.Contains(item);Retrieve the current number of items in the queue.
int currentCount = myQueue.Count;