private void deQueueThread() { try { while (BufferQueue?.Count > 0 & bStopQueue == false) { if (BufferQueue.Count > 0) { int PopSize = BufferQueue.Count; if (MaxEventSize > 0) { if (PopSize > MaxEventSize) { PopSize = MaxEventSize; } } T[] POP = new T[PopSize]; BufferQueue.TryPopRange(POP); var lPOP = POP.Where(x => x != null).ToList(); if (lPOP.Count > 0) { if (deQueue != null) { deQueue?.Invoke(lPOP, null); } } System.Threading.Thread.Sleep(Delay); } } if (bStopQueue == true) { if (QueueStopped != null) { QueueStopped.Invoke(null, null); } } } catch (Exception ex) { if (Exception != null) { Exception?.Invoke(ex, null); } } finally { bQueueProcessorActive = false; if (bStopQueue == false) { StartQueueProcessing(); } } }