private void ProcessQueue() { var added = 0; storageAdapter.Transact(() => { while (!dirsScanned && !canceled) { blockade.WaitOne(); if (dirsScanned) { break; } Flush(ref added); } TInfo item; while (infos.Count > 0 && infos.TryDequeue(out item)) { Flush(ref added); } }, true); }