Пример #1
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            ProcessControlBlock lastProcess = null;
            var begin = true;

            foreach (FrameworkElement c in canvas.Children)
            {
                if (c.Tag is ProcessControlBlock pcb)
                {
                    lastProcess = pcb;
                    begin       = true;
                    c.Width     = pcb.BurstTime * BlockFactor;
                    c.Height    = ActualHeight;
                    Canvas.SetLeft(c, pcb.DispatchTime * BlockFactor);
                }
                else if (begin)
                {
                    if (c is Line line)
                    {
                        line.X2 = line.X1 = lastProcess.DispatchTime * BlockFactor;
                        line.Y2 = ActualHeight + 6;
                    }
                    else
                    {
                        begin = false;
                        Canvas.SetLeft(c, lastProcess.DispatchTime * BlockFactor);
                        Canvas.SetTop(c, ActualHeight);
                    }
                }
                else
                {
                    if (c is Line line)
                    {
                        line.X2 = line.X1 = lastProcess.EndTime * BlockFactor;
                        line.Y2 = ActualHeight + 6;
                    }
                    else
                    {
                        Canvas.SetLeft(c, lastProcess.EndTime * BlockFactor);
                        Canvas.SetTop(c, ActualHeight);
                    }
                }
            }
        }
        protected virtual void OnDispatch(ProcessControlBlock pcb)
        {
            // 프로세스 도착 시간까지 현재 시간을 진행
            if (currentTime < pcb.Process.ArrivalTime)
            {
                currentTime = pcb.Process.ArrivalTime;
            }

            if (pcb.IsInitial)
            {
                pcb.ResponseTime = currentTime - pcb.Process.ArrivalTime;
                pcb.WaitingTime  = pcb.ResponseTime;
            }
            else
            {
                pcb.WaitingTime += currentTime - pcb.EndTime;
            }

            pcb.DispatchTime = currentTime;
            pcb.BurstTime    = 0;

            workingPcb = pcb;
        }
 /// <summary>
 /// CPU가 처리하는 프로세스가 종료되거나 준비 상태로 돌아가면
 /// result에 PCB를 추가하고 workingPcb를 비운다.
 /// </summary>
 /// <param name="pcb"></param>
 protected void Timeout()
 {
     result.Add(workingPcb);
     workingPcb = null;
 }
        private double Calculate(ProcessControlBlock pcb)
        {
            var waitingTime = currentTime - pcb.Process.ArrivalTime;

            return((double)(pcb.Process.BurstTime + waitingTime) / pcb.Process.BurstTime);
        }