Why don't WinForms / WPF elements use Invoke internally?

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)
            // do the change logic
        else
            throw new BadThreadException();
    }
}

For this:

public string Text
{
    set
    {
        if(!this.InvokeRequired)
            // do the change logic
        else
            this.Invoke(new MethodInvoker(delegate()
            {
                // do the change logic
            }
    }
}

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.

+5
3

, API . , :

1. . , , . , , , ( , ; UI , ).

2. . , , , .

3. . , UI , , . , O (n), - .

+9

, desginers , , , ( ) , . ( , ). , , , (, ), , .

+2
0
source

All Articles