5

我想知道,在调用 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();
4

1 回答 1

9

好像它会阻塞:)

看看这里:来自新线程的 Dispatcher.Invoke 正在锁定我的 UI

这里还有一些智慧:

Invoke 是同步的,而 BeginInvoke 是异步的。操作被添加到指定 DispatcherPriority 的 Dispatcher 的事件队列中。

于 2013-11-14T02:24:53.887 回答