/// <summary> /// Processes all pending tasks that can be found in the queue. /// </summary> protected internal virtual void ProcessPendingTasks() { var examinedTasks = new HashSet <Guid>(); var anyNewTasks = true; // if a task had been preserved from the previous iteration, // process it before moving forward. if (MonitorClient.CurrentTask != null) { examinedTasks.Add(MonitorClient.CurrentTask.Identifier); ProcessTask(MonitorClient.CurrentTask); } while (anyNewTasks) { anyNewTasks = false; var taskCount = MonitorClient.PendingTasks(Settings.Default.Queue).Count; for (var index = 0; index < taskCount; index++) { TaskMessage task; try { task = MonitorClient.Reserve(Settings.Default.Queue); } catch (QueueIsEmptyException) { Log.DebugFormat("No tasks in queue [{0}]", new QueueName(Settings.Default.Queue).NameWhenPending); return; } if (examinedTasks.Contains(task.Identifier)) { continue; } anyNewTasks = true; ProcessTask(task); examinedTasks.Add(task.Identifier); } } }