我想知道,当调用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();
答案 0 :(得分:7)
似乎会阻止:)
看看这里:Dispatcher.Invoke from a new thread is locking my UI
这里有更多的智慧:
Invoke是同步的,BeginInvoke是异步的。该操作将添加到Dispatcher的事件队列中指定的DispatcherPriority。