private void add_process_Click(object sender, EventArgs e) { try { if (!String.IsNullOrWhiteSpace(processName_Text.Text) && !String.IsNullOrWhiteSpace(processID_Text.Text)) { sjf.AddProcess(new ProcessDomain { ProcessName = processName_Text.Text, ProcessID = int.Parse(processID_Text.Text), CompletionTime = SimpleRandomGenerator.GetRendomTime(), Burst_Time = SimpleRandomGenerator.GetRendomTime(), ArrivalTime = SimpleRandomGenerator.GetRendomTime(), Priority = ProcessPriority.Normal, State = ProcessState.New }); processName_Text.Clear(); processID_Text.Clear(); } else { MessageBox.Show("Some input in textbox wrong"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { TimerCallback callback = null; Timer timer = null; CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; List <ProcessDomain> processes = new List <ProcessDomain> { new ProcessDomain { ProcessName = "p0", ProcessID = 4, State = ProcessState.Running, Priority = ProcessPriority.Normal }, new ProcessDomain { ProcessName = "p1", ProcessID = 5, State = ProcessState.Completed, Priority = ProcessPriority.Normal }, new ProcessDomain { ProcessName = "p2", ProcessID = 6, State = ProcessState.Completed, Priority = ProcessPriority.Normal }, new ProcessDomain { ProcessName = "p3", ProcessID = 7, State = ProcessState.Completed, Priority = ProcessPriority.Normal } }; foreach (var item in GetAllProcess(processes)) { Console.WriteLine(item); } ClockGenerator clock = new ClockGenerator(callback, timer); SJFScheduler sjf = new SJFScheduler(processes); //var runTasks = sjf.StartConvertToRunningOperation(token); //var resTask = sjf.Start(token); //nonpreemptive imitation Thread.Sleep(500); sjf.AddProcess(new ProcessDomain { ProcessName = "p3", ProcessID = 8, State = ProcessState.New, Priority = ProcessPriority.Normal }); //resTask.Wait(); //if (resTask.IsCompleted) //{ // foreach (var res in resTask.Result) // { // Console.WriteLine(res); // } //} //clock.Stop(); //Console.Read(); }