Inspired by this https://stackoverflow.com/a/5852926/291415, I made a FixedSizeQueue that will empty itself when it reaches the configured size. And it will trigger an event at the time.
public new void Enqueue( T obj )
{
base.Enqueue( obj );
lock ( syncObject )
{
if ( base.Count > Size )
{
for ( int i = 0; i < Size; i++ )
{
T outObj;
base.TryDequeue( out outObj );
ItemsList.Add( outObj );
}
OnExportItems( new ExportEventArgs<T>( ItemsList ) );
ResetItemsList();
}
}
}
And this works just fine.
But there is a case when the number of items queued is smaller than the size of the queue.
How should I flush the queue in this case? A timer that checks the queue every x milliseconds and triggers the emptying?