I understand why GUI controls have an affinity for threading.
But why don't controls use internal handling in their methods and properties?
Now you need to do something like this to update the value TextBox:
this.Invoke(new MethodInvoker(delegate()
{
textBox.Text = "newValue";
}
When used, textBox.Text = "newValue";it would only be enough to represent the same logic.
All you need to do is change the logic textBox.Textfrom this (pseudo-code):
public string Text
{
set
{
if(!this.InvokeRequired)
else
throw new BadThreadException();
}
}
For this:
public string Text
{
set
{
if(!this.InvokeRequired)
else
this.Invoke(new MethodInvoker(delegate()
{
}
}
}
The same applies to methods and techniques.
Of course, I do not propose to remove Invoke/BeginInvoke , I just ask why the controls do not execute the desired thread, instead of throwing an exception.