A Question about Control.Invoke

  • Thread starter Thread starter ozbear
  • Start date Start date
O

ozbear

I have a code sequence that goes something like this:

1. Start an asynchronous i/o with a completion callback of /cb/

Now when the i/o completes we end up in the /cb/ routine....
note that we are in a pool thread during the callback, not the
main form's thread.

2. call the Endxxxx(ar) to retrieve the results of the operation
3. form.Invoke(delegate method, params)
4. do another asynchronous i/o for more data

At step 3 we call Invoke to switch to the main form's thread and
pass it some data. This is necessary since doing anything with
form's controls outside its main thread is not safe.

My question is what is Invoke doing under the covers? Does it
just launch the delegate with the equivalent of a PostMessage or
PostThreadMessage and return straightaway so we can get the next
i/o started at step (4), or is step (4) not executed until the
delegate method (and any routines it calls in turn) in step (3)
completed?

I can change Invoke to BeginInvoke if that is what is required.

Regards, Oz
 
My question is what is Invoke doing under the covers? Does it
just launch the delegate with the equivalent of a PostMessage or
PostThreadMessage and return straightaway so we can get the next
i/o started at step (4), or is step (4) not executed until the
delegate method (and any routines it calls in turn) in step (3)
completed?

Invoke blocks until the method that you are invoking returns. If you want
your UI method invocation to return immediately, use BeginInvoke.
 
Back
Top