Created
January 31, 2021 05:48
-
-
Save heiswayi/13d6dead9fba69c18d6bbe4afef96e9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FixedSizedQueue<T> : ConcurrentQueue<T> | |
{ | |
private readonly object syncObject = new object(); | |
public int Size { get; private set; } | |
public FixedSizedQueue(int size) | |
{ | |
Size = size; | |
} | |
public new void Enqueue(T obj) | |
{ | |
base.Enqueue(obj); | |
lock (syncObject) | |
{ | |
while (base.Count > Size) | |
{ | |
T outObj; | |
base.TryDequeue(out outObj); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment