A background thread needs to update a label on the form. It generates an event. The event handler looks like this
void ShowResults(object sender,EventArgs e)
{
....
SetText( results.ToString() );
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (this.resultsLabel.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.resultsLabel.Text = text;
}
}
The label is being updated very quickly and everything seems to be working. The problem is that when I close the form the UI locks up. If I comment out the statement
SetText( results.ToString() );
Then the form closes correctly. How do I get it to close down properly?