private void WriteContactsFromQueue() { Log.Logger.Debug($"Thread {Thread.CurrentThread.ManagedThreadId} started writing..."); Contact contact; while (CurrentStatus.IsReading() || !CurrentStatus.IsQueueEmpty()) { if (CurrentStatus.TryDequeue(out contact)) { try { ProcessContact(contact); CurrentStatus.WriteCounterAdd(1); } catch (Exception ex) { HandleException(ex, contact); } } else { // Reader is running behind, give it some time Thread.Sleep(100); } } Log.Logger.Debug($"Thread {Thread.CurrentThread.ManagedThreadId} is done writing..."); }