public void ScheduleTasks() { int step = 0; int ProcessIndex = 0; List <PeriodicProcess> ProcessQueue = new List <PeriodicProcess>(); while (step < LeastCommonMultiple) { if (CPRemaining == 1) //Current Process has been finished { CurrentProcess = null; } if (CurrentProcess != null) //If there is a process running, Decrease remaining steps { CPRemaining -= 1; } else // If it is free, run a process { for (int i = 0; i < Processes.Count; i++) { if (step >= Processes[i].DeadlineStep) { Processes[i].CanProcess = true; Processes[i].NextDeadline(); } if (Processes[i].CanProcess) { ProcessQueue.Add(Processes[i]); } } if (ProcessQueue.Count > 0) { ProcessIndex = PickProcess(ProcessQueue); CurrentProcess = Processes.Find(o => o.Number == ProcessQueue[ProcessIndex].Number); CPRemaining = RunProcess(CurrentProcess); Console.WriteLine("Index: " + (CurrentProcess.Number + 1) + " on step " + step); } else { Console.WriteLine("No process executed on step " + step); } } if (CurrentProcess != null) { UIMgr.DrawRect(CurrentProcess.Number, CurrentProcess.color, step); } UIMgr.DrawStepLabel(step); ++step; ProcessQueue.Clear(); } }
public void GenerateAndRun() { for (int i = 0; i < BurstPeriodTimes.Count; i++) { PeriodicProcess pp = new PeriodicProcess(BurstPeriodTimes[i].Item1, BurstPeriodTimes[i].Item2); processes.Add(pp); } // Generating the process manager, giving the list as the parameter try { PeriodicProcessManager ProcessMgr = new PeriodicProcessManager(processes); ProcessMgr.ScheduleTasks(); } catch (Exception ex) { Console.WriteLine(ex); } }
int RunProcess(PeriodicProcess _process) { _process.CanProcess = false; return(_process.ExecutionTime); }