private void FireReadyJobs() { var items = m_items; var itemStatus = m_itemStatus; lock (m_itemStatus) { // loop over all items for (int a = 0; a < itemStatus.Length; a++) { // only consider items that are waiting var status = itemStatus[a]; if (status != ItemStatus.Waiting) { continue; } int aoff = a * items.Length; bool canARun = true; // compare to all other items; can this be run? for (int b = 0; b < itemStatus.Length; b++) { if (a == b) { continue; } var bstatus = itemStatus[b]; var order = m_order[aoff + b]; if (order == ScheduleOrder.AnyOrderConcurrent) { continue; } if (order == ScheduleOrder.RunAfter) // A has to run after B { if (bstatus != ItemStatus.Done) { canARun = false; break; } continue; } if (order == ScheduleOrder.RunBefore) // A has to run before B { continue; } if (order == ScheduleOrder.AnyOrderNotConcurrent) { if (bstatus == ItemStatus.Running) { canARun = false; break; } } } if (canARun) { // YES! Run this item var item = items[a]; itemStatus[a] = ItemStatus.Running; JobService.Enqueue(item.Name, RunItem, item); } } } }