private void showList(ProcessSimulation result) { timeLabel.Text = "CPU时间: " + result.Time.ToString(); efficiencyLabel.Text = "CPU利用率:" + (result.ActualRunningTime * 1.0 / Math.Max(result.Time, 1) / result.Core).ToString("0.##%"); #region 进程表格 runningView.Items.Clear(); readyView.Items.Clear(); blockView.Items.Clear(); finishView.Items.Clear(); List <Process> tmpList = result.runningPool; for (int i = 0; i < tmpList.Count(); i++) { ListViewItem tmp = new ListViewItem(tmpList[i].Name, 0); tmp.SubItems.Add(runningType == 1 ? "-" : tmpList[i].Priority.ToString()); tmp.SubItems.Add(tmpList[i].Createtime.ToString()); tmp.SubItems.Add(tmpList[i].Runningtime.ToString()); tmp.SubItems.Add((tmpList[i].Cputime - tmpList[i].Needtime).ToString()); tmp.SubItems.Add(tmpList[i].Needtime.ToString()); runningView.Items.Add(tmp); } tmpList = result.readyPool.Array(); for (int i = 0; i < tmpList.Count(); i++) { ListViewItem tmp = new ListViewItem(tmpList[i].Name, 0); tmp.SubItems.Add(runningType == 1 ? "-" : tmpList[i].Priority.ToString()); tmp.SubItems.Add(tmpList[i].Createtime.ToString()); tmp.SubItems.Add((tmpList[i].Cputime - tmpList[i].Needtime).ToString()); tmp.SubItems.Add(tmpList[i].Needtime.ToString()); readyView.Items.Add(tmp); } tmpList = result.blockedPool; for (int i = 0; i < tmpList.Count(); i++) { ListViewItem tmp = new ListViewItem(tmpList[i].Name, 0); tmp.SubItems.Add(runningType == 1 ? "-" : tmpList[i].Priority.ToString()); tmp.SubItems.Add(tmpList[i].Createtime.ToString()); tmp.SubItems.Add((tmpList[i].Cputime - tmpList[i].Needtime).ToString()); tmp.SubItems.Add(tmpList[i].Needtime.ToString()); blockView.Items.Add(tmp); } tmpList = result.finishedPool; for (int i = 0; i < tmpList.Count(); i++) { ListViewItem tmp = new ListViewItem(tmpList[i].Name, 0); tmp.SubItems.Add(runningType == 1 ? "-" : tmpList[i].Priority.ToString()); tmp.SubItems.Add(tmpList[i].Createtime.ToString()); tmp.SubItems.Add((tmpList[i].Cputime - tmpList[i].Needtime).ToString()); finishView.Items.Add(tmp); } #endregion #region 拉框 tmpList = result.runningPool; runningBox.Items.Clear(); runningBox.Items.AddRange(tmpList.Select(u => u.Name).ToArray()); tmpList = result.blockedPool; blockBox.Items.Clear(); blockBox.Items.AddRange(tmpList.Select(u => u.Name).ToArray()); #endregion }
public static void Shut() { if (processSimulation != null && !processSimulation.IsStoped()) { processSimulation.Pause = true; } processSimulation = null; }
public static void CreateProcessSimulation(bool isPriority, List <Process> processes, int speed = 1, int core = 1) { if (isPriority) { processSimulation = new PriorityProcessSimulation(speed, core); } else { processSimulation = new QueueProcessSimulation(speed, core); } processSimulation.OneStepWent += Solve; processSimulation.Pause = true; processSimulation.InsertIntoWaitingPool(processes); }
public static void Solve(ProcessSimulation ps) { ToForm?.Invoke(ps); }