The concepts of BeginInvoke and Invoke can be represented as follows.
- BeginInvoke means: "Do this and return before it completes. I either do not care about the return value, or you can call me back at this address at some point in the future."
- Invoke means: "Do it, and I'll sit here and wait for it to complete."
Now, as it relates to dispatchers and background threads, this is a completely different matter. According to Justin, the dispatcher processes the queue of things every time the UI thread becomes inactive. The background thread that calls BeginInvoke in the dispatcher will immediately return, even if the dispatcher may not have accessed the processing. If Invoke was used instead, the background thread blocked until the user interface processing was complete. Note that there is no Invoke in Silverlight in Dispatcher, and in most cases you probably don't want to block the background thread while the user interface thread is processing the work.
Conversely, Delegate.BeginInvoke uses worker threads in a thread pool. When you are in a user interface thread (or in any thread), you can invoke BeginInvoke and Invoke on the delegate. BeginInvoke will use the workflow to invoke the delegate using the same semantics as I described above. The call, however, will not use another thread. It simply called the delegate synchronously in the context of the calling thread and returned after completion.
Be careful when using synchronous execution on threads, although this often leads to deadlocks if you are not very careful.
Josh
source share