0% found this document useful (0 votes)
5 views3 pages

NonPreemp (CPU Scheduling)

The document is a C# Windows Forms application that implements a non-preemptive priority scheduling algorithm for processes. It allows users to add, edit, and remove processes, displaying their attributes such as Process ID, Arrival Time, Burst Time, and Priority in a DataGridView. The application calculates and displays the Completion Time, Turnaround Time, and Waiting Time for each process after scheduling.

Uploaded by

Joemar Lagbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

NonPreemp (CPU Scheduling)

The document is a C# Windows Forms application that implements a non-preemptive priority scheduling algorithm for processes. It allows users to add, edit, and remove processes, displaying their attributes such as Process ID, Arrival Time, Burst Time, and Priority in a DataGridView. The application calculates and displays the Completion Time, Turnaround Time, and Waiting Time for each process after scheduling.

Uploaded by

Joemar Lagbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Collections.Specialized.BitVector32;
using System.Xml.Linq;

namespace PriorityFirst_Non_Preemptive
{
public partial class Form1 : Form
{
private List<Process> processes = new List<Process>();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private class Process


{
public int ProcessID { get; set; }
public int ArrivalTime { get; set; }
public int BurstTime { get; set; }
public int Priority { get; set; }
public int CompletionTime { get; set; }
public int TurnaroundTime { get; set; }
public int WaitingTime { get; set; }

private void Addbtn_Click(object sender, EventArgs e)


{
try
{
Process newProcess = new Process()
{

ProcessID = int.Parse(ProcessID1.Text),
ArrivalTime = int.Parse(ArrivalTime1.Text),
BurstTime = int.Parse(BurstTime1.Text),
Priority = int.Parse(Priority1.Text)

};
processes.Add(newProcess);
{
UpdateDataGridView();

}
catch (Exception)
{
MessageBox.Show("Unexpected error occur");
}

private void UpdateDataGridView()


{
Display.Rows.Clear();
foreach (var process in processes)
{
Display.Rows.Add(process.ProcessID, process.ArrivalTime, process.BurstTime,
process.Priority);
ProcessID1.Clear();
ArrivalTime1.Clear();
BurstTime1.Clear();
Priority1.Clear();
}
}

private void Schedulebtn_Click(object sender, EventArgs e)


{
processes = processes.OrderBy(p => p.ArrivalTime).ThenBy(p => p.Priority).ToList();
int currentTime = 0;
foreach (var process in processes)
{
process.CompletionTime = currentTime + process.BurstTime;
process.TurnaroundTime = process.CompletionTime - process.ArrivalTime;
process.WaitingTime = process.TurnaroundTime - process.BurstTime;
currentTime = process.CompletionTime;

}
UpdateDataGridViewWithSchedule();
}

private void UpdateDataGridViewWithSchedule()


{
Display.Rows.Clear();
foreach (var process in processes)
{
Display.Rows.Add(process.ProcessID, process.ArrivalTime, process.BurstTime,
process.Priority,
process.CompletionTime, process.TurnaroundTime, process.WaitingTime);
}
}

private void btnEdit_Click(object sender, EventArgs e)


{
if (Display.CurrentRow != null)
{
Display.CurrentRow.Cells["ProsessIDCol"].Value = ProcessID1.Text;
Display.CurrentRow.Cells["ArrivalTimeCol"].Value = ArrivalTime1.Text;
Display.CurrentRow.Cells["BurstTimeCol"].Value = BurstTime1.Text;
Display.CurrentRow.Cells["Priority"].Value = Priority1.Text;

}
}

private void Clearbtn_Click(object sender, EventArgs e)


{
if (Display.CurrentRow != null)
{
Display.Rows.RemoveAt(Display.CurrentRow.Index);

}
}
}
}

You might also like