public void Run() { while (ActiveProcess.Status == ComputerStatus.Running || ActiveProcess.Status == ComputerStatus.Waiting || WaitingProcesses.Keys.ToList().Any()) { if (ActiveProcess.Status == ComputerStatus.Running) { ActiveProcess.Start(); } else if (ActiveProcess.Status == ComputerStatus.Waiting) { SetSharedMemory(ActiveProcess.DumpOutput()); WaitingProcesses.Add(ActiveProcess.WaitingSince, ActiveProcess.Identifier); ActiveProcess = GetLongestWaitingProcess(); ActiveProcess.setInput(GetSharedMemory(ActiveProcess.Identifier)); } else { SetSharedMemory(ActiveProcess.DumpOutput()); ActiveProcess = GetLongestWaitingProcess(); ActiveProcess.setInput(GetSharedMemory(ActiveProcess.Identifier)); } } LastOutput = ActiveProcess.DumpOutput().Item1; }
private IProcess GetLongestWaitingProcess() { var longestWaitingDateTime = WaitingProcesses.Keys.ToList().Min(); var process = AllProcesses[WaitingProcesses[longestWaitingDateTime]]; process.Status = ComputerStatus.Running; WaitingProcesses.Remove(longestWaitingDateTime); return(process); }
public void QueueProcess(IProcess process) { process.Status = ComputerStatus.Waiting; AllProcesses.Add(process.Identifier, process); WaitingProcesses.Add(DateTime.Now, process.Identifier); }