C
Code Monkey
Suppose I have a windows form (.exe) that has a load of labels and
text boxes on it.
I enter a number into one of the text boxes and hit the search button.
This then launches another thread, which may or may not spawn other
threads.
What's the best way of updating the user interface?
BackgroundWorker?
or calling something like
SetText("something", myControl);
for each control that I want to set the text for?
Bearing in mind that we're updating the user interface on a different
thread than what it was started on.
<code>
private delegate void SetTextCallback(string text, Control
controlName);
private void SetText(string text, Control controlName)
{
if (controlName.InvokeRequired)
{
SetTextCallback d = SetText;
Invoke(d, new object[] {text, controlName});
}
else
{
controlName.Text = text;
}
}
</code>
text boxes on it.
I enter a number into one of the text boxes and hit the search button.
This then launches another thread, which may or may not spawn other
threads.
What's the best way of updating the user interface?
BackgroundWorker?
or calling something like
SetText("something", myControl);
for each control that I want to set the text for?
Bearing in mind that we're updating the user interface on a different
thread than what it was started on.
<code>
private delegate void SetTextCallback(string text, Control
controlName);
private void SetText(string text, Control controlName)
{
if (controlName.InvokeRequired)
{
SetTextCallback d = SetText;
Invoke(d, new object[] {text, controlName});
}
else
{
controlName.Text = text;
}
}
</code>