I have a simple program which loops through a resultset when a button is pressed and performs actions against this resultset (stored in a DataTable
). During the loop I update the text of a RichTextBox
, 2 labels, and a ToolStripStatusLabel
. These are not refreshing during the loop so after each item is processed in the loop I do a this.Refresh()
. This works unless I click on anything in the program, at which time it says it's not responding, and nothing is refreshed in the form until the foreach
loop completes.
private void myBtn_Click(object sender, EventArgs e)
{
// Query database and store results in DataTable dt.
foreach (DataRow dr in dt.Rows)
{
// Process row data.
// Update RichTextBox, labels, and ToolStripStatusLabel.
this.Refresh();
}
}
Is something wrong here? Is there a better way to do this? This is a Windows Forms application using C#.