5

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();
Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • Why won't you try it? Add a sleep of a couple of seconds inside the invoke, another line out of it, and see if it hits it before it's done ... – Noctis Nov 14 '13 at 02:19
  • @Noctis You know what, I am so tired right now that...that didn't even cross my mind, but I'll give it a shot I guess. It wouldn't hurt to have someone reference some tangible documentation on this though :P – Alexandru Nov 14 '13 at 02:20
  • 1
    Nothing like coding into the small hours, eh? – Noctis Nov 14 '13 at 02:22
  • Nah ...just answered your question for you ... it's back to the code mines for you ! – Noctis Nov 14 '13 at 02:25

1 Answers1

9

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.

Community
  • 1
  • 1
Noctis
  • 11,507
  • 3
  • 43
  • 82