private WaitCallback SaveVisitData(EventWaitHandle queueMgmt) { return(state => { while (true) { byte[] data; while (!_messageQueue.TryDequeue(out data)) { _persistance.AdviseNoVisitData(); ThreadHelper.YieldOrSleep(100); } _perfCounters.CurrentMemoryQueueSize = _messageQueue.Count; _perfCounters.IncrementBlocksReceived(); if (data.Length == 0) { _communicationManager.Complete(); queueMgmt.Set(); return; } _persistance.SaveVisitData(data); } }); }