WPF 中的 Dispatcher Object 有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/159015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:40:55  来源:igfitidea点击:

What is the use of a Dispatcher Object in WPF?

wpfdispatcher

提问by mrbradleyt

What is the use of a Dispatcher Object in WPF?

WPF 中的 Dispatcher Object 有什么用?

采纳答案by GEOCHET

A dispatcher is often used to invoke calls on another thread. An example would be if you have a background thread working, and you need to update the UI thread, you would need a dispatcher to do it.

调度程序通常用于调用另一个线程上的调用。一个例子是,如果您有一个后台线程在工作,并且您需要更新 UI 线程,则您需要一个调度程序来执行此操作。

回答by arik

Almost every WPF element has thread affinity. This means that access to such an element should be made only from the thread that created the element. In order to do so, every element that requires thread affinity is derived, eventually, from DispatcherObject class. This class provides a property named Dispatcher that returns the Dispatcher object associated with the WPF element.

几乎每个 WPF 元素都具有线程关联性。这意味着只能从创建该元素的线程访问此类元素。为此,每个需要线程关联的元素最终都是从 DispatcherObject 类派生的。此类提供了一个名为 Dispatcher 的属性,该属性返回与 WPF 元素关联的 Dispatcher 对象。

The Dispatcher class is used to perform work on his attached thread. It has a queue of work items and it is in charge of executing the work items on the dispatcher thread.

Dispatcher 类用于在他的附加线程上执行工作。它有一个工作项队列,负责在调度程序线程上执行工作项。

You can find on the following link some more details on the subject: http://blogs.microsoft.co.il/blogs/arik/archive/2010/08/12/wpf-inside-out-dispatcher.aspx

您可以在以下链接中找到有关该主题的更多详细信息:http: //blogs.microsoft.co.il/blogs/arik/archive/2010/08/12/wpf-inside-out-dispatcher.aspx