예제 #1
0
        public void Step()
        {
            if (InProgress != null)
            {
                if (InProgress.Done)
                {
                    InProgress = null;
                }
                else if (InProgressTime == ExecTime)
                {
                    Ready.Add(InProgress);
                    InProgress = null;
                }
            }

            for (int i = 0; i < Tasks.Count; i++)
            {
                if (Tasks[i].LaunchTime == Time)
                {
                    Ready.Add(Tasks[i]);
                    Tasks.RemoveAt(i--);
                }
            }

            if (Time % PriorityUpdateInterval == 0)
            {
                UpdatePriorities();
            }

            Ready.Sort();

            if (InProgress == null && Ready.Count > 0)
            {
                InProgress = Ready.Last();
                Ready.Remove(InProgress);
                InProgressTime = 0;
            }

            if (InProgress != null)
            {
                InProgress.Execute(1);
                InProgressTime++;
            }

            if (Logging)
            {
                List <string> readyTasks = new List <string>();
                foreach (var task in Ready)
                {
                    readyTasks.Add(task.Name);
                }

                string inProg = "";
                if (InProgress != null)
                {
                    inProg = InProgress.Name;
                }
                LogTable.Add(new LogNode(Time, inProg, readyTasks));
            }

            Time++;
        }