private void OnEndOfShift(WorkShift endingShift) { ShiftFinished?.Invoke(endingShift); WorkShift nextShift = null; while (true) { // Shift has ended but all work may not yet be done while (_topLevelWorkItem.State != WorkItemState.Complete) { // This will return null if all queues are empty. nextShift = SelectNextShift(); if (nextShift != null) { ShiftStarting?.Invoke(nextShift); nextShift.Start(); return; } } // If the shift has ended for an isolated queue, restore // the queues and keep trying. Otherwise, we are done. if (_isolationLevel > 0) { RestoreQueues(); } else { break; } } // All done - shutdown all shifts foreach (var shift in Shifts) { shift.ShutDown(); } }