I solved the problems. It caused by backgroundworker. I do not know how to explain the concept technicaly. But, here that I did.
I move the LoadInputData();
line. Previously, I put it inside private void OpenDataBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
function. Then, I moved it to the another place outside the background worker. It can seen in this code below.
Previously: (see the "//")
private void OpenDataBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
try
{
//LoadInputData();
CalculateRowAndColumnInNumericUpDown();
mainForm.MainToolStripProgressBar.Value = 0;
this.Cursor = Cursors.Default;
OpenDataButton.Enabled = true;
ProcessGroupBox.Enabled = true;
ClearAllDataButton.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Open Data Background Worker RunWorkerCompleted Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
To this place:
private void OpenDataButton_Click(object sender, EventArgs e)
{
try
{
OpenDataButton.Enabled = false;
if (!OpenDataBackgroundWorker.IsBusy)
{
OpenFileDialog openData = new OpenFileDialog();
openData.Multiselect = true;
openData.ShowDialog();
openData.Filter = "allfiles|*";
if (openData.FileName != "")
{
ClearInputDataTable();
LoadInputData();
OpenDataBackgroundWorker.WorkerReportsProgress = true;
OpenDataBackgroundWorker.WorkerSupportsCancellation = true;
OpenDataBackgroundWorker.RunWorkerAsync(openData.FileName);
}
}
//here!!!
LoadInputData();
OpenDataButton.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error - Open Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}