Dispatcher.Invoke阻塞调用线程吗?

时间:2013-11-14 02:13:58

标签: c# .net wpf multithreading dispatcher

我想知道,当调用Dispatcher.Invoke时,调用线程是否会等到调度程序完成其操作...?

例如:

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();

1 个答案:

答案 0 :(得分:7)

似乎会阻止:)

看看这里:Dispatcher.Invoke from a new thread is locking my UI

这里有更多的智慧:

  

Invoke是同步的,Be​​ginInvoke是异步的。该操作将添加到Dispatcher的事件队列中指定的DispatcherPriority。