private void Run(object obj) { do { Status = WorkerStatus.Processing; IsWorking = true; try { TItem item; while (Bucket.Items.TryDequeue(out item)) { CurrentItem = item; Bucket.Action(item, Bucket.Context); } } finally { Status = WorkerStatus.Waiting; CurrentItem = null; IsWorking = false; _isRunning.Release(); } } while (Bucket.Items.Count > 0 && _isRunning.WaitOne()); }