I am trying to read a "csv file", then save it's data into an employee
record, then adding this record into a list
, then adding the list into a data table
and finally display the datatables content inside a datagridview
.
I can't seem to figure out if I have an endless loop running or what the problem may be. The program runs for 1 minute then throws the error 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;
}
}