public void ExecutionComplete(RayDispatch dispatch) { lock (dispatches) { dispatches.Remove(dispatch); // check for queued items to replace thread with lock (instQueue) { if (instQueue.Count > 0) { RayGroup group = (RayGroup)instQueue.Dequeue(); dispatches.Add(new RayDispatch(group.Trace, group, this)); } } processedThreads++; } }