c# - Dispatcher.Invoke 是否在调用线程上阻塞?

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

最佳答案

好像会阻塞:)

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

这里还有一些智慧:

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

关于c# - Dispatcher.Invoke 是否在调用线程上阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19968253/

相关文章:

c# - Chrome 在 div 之外溢出 iframe 背景?

c# - 正则表达式 - 如何忽略以下划线开头的字符串

c# - 确保语句未优化 "away"

c# - 在标题中使用 '/' 时如何防止列不显示在 WPF 数据网格中?

wpf - 如何将顶级 MenuItem 上的 Visibility 属性绑定(bind)到 ViewModel

wpf - 带有过滤器行的数据网格

c# - 使用 DllImport 将返回的 char* 从 C++ 传递到 C#

c# - NetSuite 自定义记录搜索将结果转换为 .NET 对象列表

c# - 在 WCF 服务应用程序中找不到类型或命名空间名称 'var'

c# - FileStream.Dispose 是否立即关闭文件?