public static void Execute(ref InternalWorkItem <T> item) { #if DEBUG if (!item.Valid) { throw new WorkQueueException(item.Queue, "Invalid work item"); } #endif item.Data.Execute(); if (item.OnComplete != null) { item.OnComplete(ref item.Data); } }
public int Step(out bool exhausted, int?maximumCount = null) { int result = 0, count = 0; int actualMaximumCount = maximumCount.GetValueOrDefault(DefaultStepCount); InternalWorkItem <T> item = default(InternalWorkItem <T>); bool running = true; do { lock (Queue) { running = ((count = Queue.Count) > 0) && (result < actualMaximumCount); if (running) { InFlightTasks++; item = Queue.Dequeue(); } } if (running) { item.Data.Execute(); if (item.OnComplete != null) { item.OnComplete(ref item.Data); } result++; lock (Queue) { InFlightTasks--; if ((Queue.Count == 0) && (InFlightTasks <= 0)) { DrainComplete.Set(); } } } } while (running); lock (Queue) exhausted = Queue.Count == 0; return(result); }