Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Dispatcher.Invoke block on the calling thread?

I was wondering if, when calling Dispatcher.Invoke, the calling thread would wait until the dispatcher finished its operation or not...?

For example:

new Thread(() =>
{
   string x = "Yes.";
   // Invoke the dispatcher.
   Dispatcher.Invoke((Action)delegate()
   {
      // Get the string off a UI element which contains the text, "No."
      x = textBox.Text;
   });
   // Is x either ("Yes" or "No") here, or always "No"?
}).Start();
like image 991
Alexandru Avatar asked Nov 14 '13 02:11

Alexandru


1 Answers

Seems like it will block :)

Have a look here: Dispatcher.Invoke from a new thread is locking my UI

Here's some more wisdom:

Invoke is synchronous and BeginInvoke is asynchronous. The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

like image 62
Noctis Avatar answered Sep 24 '22 01:09

Noctis