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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top