我正在尝试读取“csv 文件”,然后将其数据保存到employee
记录中,然后将此记录添加到 alist
中,然后将列表添加到 a 中data table
,最后在 a 中显示数据表内容datagridview
。我似乎无法弄清楚我是否正在运行无限循环或问题可能是什么。程序运行 1 分钟,然后抛出错误ContextSwitchDeadlock。
private void searchButton_Click(object sender, EventArgs e)
{
string headerLine = reader.ReadLine();
openFileDialog1.ShowDialog();
searchValue.Text = openFileDialog1.FileName;
using (StreamReader reader = new StreamReader(openFileDialog1.FileName))
{
var line = reader.ReadLine();
var value = line.Split(',');
while(!reader.EndOfStream)
{
List<Employee> employeeList = new List<Employee>();
var newEmployee = new Employee();
newEmployee.firstName = value[0];
newEmployee.lastName = value[1];
newEmployee.address = value[2];
newEmployee.age = value[3];
newEmployee.monthlyGrossIncome = value[4];
newEmployee.departmentId = value[5];
newEmployee.developerType = value[6];
newEmployee.taxType = value[7];
}
DataTable dataTable = new DataTable();
dataTable.Columns.Add(headerLine);
employeeDataGridView.DataSource = dataTable;
}
}