CS0122 Form1.AvgWaiting由于其保护级别和C#Windows窗体中的甘特图而无法访问
我目前正在为我的学校项目创建一个CPU调度模拟器程序。目前,我有以下错误: CS0122 Form1.AvgWaiting由于其保护级别而不可访问 当我将文本框从Form1Designer.cs更改为public时,会出现以下错误: CS0120 C#非静态字段、方法或属性需要对象引用 我有Form1.cs和一个单独的算法类。我将使用我的算法来显示datagridview和textbox的输出 我的Form1.csCS0122 Form1.AvgWaiting由于其保护级别和C#Windows窗体中的甘特图而无法访问,c#,algorithm,winforms,windows-forms-designer,job-scheduling,C#,Algorithm,Winforms,Windows Forms Designer,Job Scheduling,我目前正在为我的学校项目创建一个CPU调度模拟器程序。目前,我有以下错误: CS0122 Form1.AvgWaiting由于其保护级别而不可访问 当我将文本框从Form1Designer.cs更改为public时,会出现以下错误: CS0120 C#非静态字段、方法或属性需要对象引用 我有Form1.cs和一个单独的算法类。我将使用我的算法来显示datagridview和textbox的输出 我的Form1.cs using System; using System.Collections.G
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CPU_Scheduling_Simulator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// set default values to comboBox
foreach (Control cont in this.Controls)
{
if (cont is ComboBox)
{
((ComboBox)cont).SelectedIndex = 0;
}
}
}
public void Form1_Load(object sender, EventArgs e)
{
}
public void groupBox2_Enter(object sender, EventArgs e)
{
}
public void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
Close();
}
public void buttonGenerate_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
int count = int.Parse(comboBoxProcess.GetItemText(comboBoxProcess.SelectedItem));
if (comboBoxProcess.SelectedIndex == -1)
MessageBox.Show("Please select num of Process");
else
{
dataGridView1.Rows.Add(count);
for (int i = 0; i < count; i++)
{
dataGridView1.Rows[i].Cells["Processes"].Value = "" + (i+1);
}
}
}
public void buttonClear_Click(object sender, EventArgs e)
{
foreach (Control control in this.Controls)
{
if (control is TextBox)
((TextBox)control).Text = null;
}
dataGridView1.Rows.Clear();
}
public void groupBox5_Enter(object sender, EventArgs e)
{
}
public void buttonSimulate_Click(object sender, EventArgs e)
{
int count = int.Parse(comboBoxProcess.GetItemText(comboBoxProcess.SelectedItem));
int index = comboBoxAlgorithm.SelectedIndex;
switch (index)
{
case 0:
// Process id's
int[] processes = new int[count];
int n = processes.Length;
// Burst time of all processes
int[] burst_time = new int[n];
for (int x = 0; x < n; x++)
burst_time[x] = int.Parse((string)dataGridView1.Rows[x].Cells["BurstTime"].Value);
// Arrival time of all processes
int[] arrival_time = new int[n];
for (int x = 0; x < n; x++)
arrival_time[x] = int.Parse((string)dataGridView1.Rows[x].Cells["ArrivalTime"].Value);
FCFS.findavgTime(processes, n, burst_time, arrival_time);
break;
default:
MessageBox.Show("Please select an Algorithm");
break;
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间CPU_调度_模拟器
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
//将默认值设置为comboBox
foreach(此控件中的控件cont)
{
if(cont是组合框)
{
((组合框)续)。选择索引=0;
}
}
}
public void Form1_Load(对象发送方、事件参数e)
{
}
public void groupBox2_Enter(对象发送方,事件参数e)
{
}
public void dataGridView1\u CellContentClick(对象发送者,DataGridViewCellEventArgs e)
{
}
公共无效按钮1\u单击(对象发送者,事件参数e)
{
Close();
}
公共无效按钮生成单击(对象发送者,事件参数e)
{
dataGridView1.Rows.Clear();
int count=int.Parse(comboBoxProcess.GetItemText(comboBoxProcess.SelectedItem));
如果(comboBoxProcess.SelectedIndex==-1)
MessageBox.Show(“请选择进程数”);
其他的
{
dataGridView1.Rows.Add(计数);
for(int i=0;i
}
我的FCFS.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CPU_Scheduling_Simulator
{
public class FCFS
{
// Function to find the waiting time for all
// processes
public static void findWaitingTime(int[] processes, int n, int[] bt, int[] wt, int[] at)
{
int[] service_time = new int[n];
service_time[0] = 0;
wt[0] = 0;
// calculating waiting time
for (int i = 1; i < n; i++)
{
// Add burst time of previous processes
service_time[i] = service_time[i - 1] + bt[i - 1];
// Find waiting time for current process =
// sum - at[i]
wt[i] = service_time[i] - at[i];
// If waiting time for a process is in negative
// that means it is already in the ready queue
// before CPU becomes idle so its waiting time is 0
if (wt[i] < 0)
wt[i] = 0;
}
}
// Function to calculate turn around time
public static void findTurnAroundTime(int[] processes, int n, int[] bt,
int[] wt, int[] tat)
{
// Calculating turnaround time by adding bt[i] + wt[i]
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
}
// Function to calculate average waiting and turn-around
// times.
public static void findavgTime(int[] processes, int n, int[] bt, int[] at)
{
int[] wt = new int[n]; int[] tat = new int[n];
// Function to find waiting time of all processes
findWaitingTime(processes, n, bt, wt, at);
// Function to find turn around time for all processes
findTurnAroundTime(processes, n, bt, wt, tat);
// Display processes along with all details
//Console.Write("Processes " + " Burst Time " + " Arrival Time "
// + " Waiting Time " + " Turn-Around Time "
// + " Completion Time \n");
int total_wt = 0, total_tat = 0;
for (int i = 0; i < n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
int compl_time = tat[i] + at[i];
//Console.WriteLine(i + 1 + "\t\t" + bt[i] + "\t\t"
// + at[i] + "\t\t" + wt[i] + "\t\t "
// + tat[i] + "\t\t " + compl_time);
Form1.dataGridView1.Rows[i].Cells["Processes"].Value = i + 1;
Form1.dataGridView1.Rows[i].Cells["BurstTime"].Value = bt[i];
Form1.dataGridView1.Rows[i].Cells["ArrivalTime"].Value = at[i];
Form1.dataGridView1.Rows[i].Cells["WaitingTime"].Value = wt[i];
}
//Console.Write("Average waiting time = "
// + (float)total_wt / (float)n);
//Console.Write("\nAverage turn around time = "
// + (float)total_tat / (float)n);
Form1.AvgWaiting.Text = ""+(float)total_wt / (float)n);
Form1.AvgTurnaround.Text ""+(float)total_tat / (float)n);
}
// Driver code
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间CPU_调度_模拟器
{
公共类FCFS
{
//函数查找所有用户的等待时间
//进程
公共静态void findWaitingTime(int[]进程,int n,int[]bt,int[]wt,int[]at)
{
int[]服务时间=新的int[n];
服务时间[0]=0;
wt[0]=0;
//计算等候时间
对于(int i=1;ivar f1 = Application.OpenForms.OfType<Form1>().FirstOrDefault();
if(f1 != null)
{
// use f1 wherever you use Form1.
}
FCFS.findavgTime(processes, n, burst_time, arrival_time, this);
break;
public static void findavgTime(int[] processes, int n, int[] bt, int[] at, Form1 f1)
{
// and again use f1 instead of Form1