public void ProcessorScheduling()
        {
            //开始进程调度
            while (ReadyList.Count > 0)
            {
                RunningProcess = ReadyList[0];
                lock (ReadyList)
                {
                    ReadyList.RemoveAt(0);
                }

                Prompt($"当前运行进程为{RunningProcess.Name}\n");

                ReadyDraw(ReadyList);
                RunningDraw(RunningProcess);
                RunningProcess.Run();

                //一段很不好的等待方法,很粗暴
                DateTime now = DateTime.Now;
                DateTime end = now.AddSeconds(2);
                do
                {
                } while((DateTime.Now - end).Seconds < 0);

                if (RunningProcess.state == STATE.FINISH)
                {
                    FinishedList.Add(RunningProcess);

                    Prompt($"进程{RunningProcess.Name}运行结束\n");

                    RunningProcess = null;
                    FinishedDraw(FinishedList);
                    RunningDraw(RunningProcess);
                }
                else
                {
                    lock (ReadyList)
                    {
                        ReadyList.Add(RunningProcess);
                        ReadyList = SortListByPriority(ReadyList);
                    }

                    Prompt($"进程{RunningProcess.Name}重新插入到就绪队列\n");
                    Prompt($"当前优先数为{RunningProcess.priority},剩余运行时间为{RunningProcess.requestTime}\n");

                    RunningProcess = null;
                    ReadyDraw(ReadyList);
                    RunningDraw(RunningProcess);
                }

                //一段很不好的等待方法,很粗暴
                now = DateTime.Now;
                end = now.AddSeconds(2);
                do
                {
                } while((DateTime.Now - end).Seconds < 0);
            }

            Prompt("就绪队列为空,所有进程运行结束\n");
        }
        public void AddReadyProcess(string name, int priority, int time)
        {
            Process p = new Process(name, priority, time);

            lock (ReadyList)
            {
                ReadyList.Add(p);
                ReadyList = SortListByPriority(ReadyList);
            }
            Prompt($"进程{name}加入就绪队列\n");
            ReadyDraw(ReadyList);
        }
Beispiel #3
0
 private void CounterEllapsed(Transportation source)
 {
     ReadyList.Add(source);
     WaitingList.Remove(source);
 }
Beispiel #4
0
        private void Executor_StatusChanged(object sender, EventArgs e)
        {
            try
            {
                ExecutorClass            Executor = (ExecutorClass)sender;
                RequestedSubProgramClass root     = Executor.RequestedRecipe.RequestedSubProgram;
                switch (Executor.Status)
                {
                case ExecutorStatus.Ready:
                    WaitingList.Remove(root);
                    ReadyList.Add(root);
                    break;

                case ExecutorStatus.Executing:
                    ReadyList.Remove(root);
                    RunningList.Add(root);
                    break;

                case ExecutorStatus.Completed:
                    RunningList.Remove(root);
                    if (root.RequestedRecipes.Count == 1)
                    {
                        CompletedList.Add(root);
                    }
                    else if (root.RequestedRecipes.Count > 1)
                    {
                        WaitingList.Insert(0, root);
                    }
                    break;

                case ExecutorStatus.Abandoned:
                    if (ReadyList.Contains(root))
                    {
                        ReadyList.Remove(root);
                    }
                    else if (WaitingList.Contains(root))
                    {
                        WaitingList.Remove(root);
                    }
                    else if (RunningList.Contains(root))
                    {
                        RunningList.Remove(root);
                    }
                    else if (CompletedList.Contains(root))
                    {
                        CompletedList.Remove(root);
                    }
                    break;

                case ExecutorStatus.Invalid:
                    Executor.RequestedRecipe.AddExecutor();
                    if (CompletedList.Contains(root))
                    {
                        CompletedList.Remove(root);
                        WaitingList.Insert(0, root);        //back to the top by default
                    }
                    else if (RunningList.Contains(root))
                    {
                        RunningList.Remove(root);
                        WaitingList.Insert(0, root);        //back to the top by default
                    }
                    break;
                }
            }
            catch
            {
                //sender is not a ExecutorClass type
                return;
            }
        }