Question for Invoke

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a form called "frm", if there is a text box called "txtBox".

When I want to update the text box by another thread, I need invoke a method to update the text box.
The delegate method may be "UpdateTextBox".

Now, another thread can call frm.BeginInvoke or txtBox.BeginInvoke to call the UpdateTextBox method. Actually, I find that both BeginInvoke can also work. What is the different?

Thanks
 
A Control instance's BeginInvoke method simply asks the UI thread (that owns
the control) to execute the specified code when it gets time (via the
message pump). Both the Form and the TextBox are Controls, so both have this
method.

In WinForm programming, child controls *must* be owned by the same thread as
the parent, so in this case frm.BeginInvoke() and txtBox.BeginInvoke() will
do *exactly* the same thing.

Does that make sense?

Marc
 
Back
Top