调度主题在WPF关系关系、主题、WPF

2023-09-02 10:46:55 作者:笑我活該

这是不完全清楚,我有多少调度员有一个应用程序以及它们之间的关系,或从线程引用。

据我所知,WPF应用程序有2个线程(一个用于输入,另一个用于UI)和1个调度员(关联到UI线程)。如果我创建另一个线程 - 我们称之为工作线程 - 当我打电话 Dispatcher.CurrentDispatcher 的工作线程,即调度会,我得到

吗?

另外一种情况: 假设2个线程的控制台应用程序 - 主线程和输入线程。在主线程,我首先创建输入线程,然后我叫 Application.Run()

 线程的线程=新主题(新的ThreadStart(UserInputThreadFunction));
thread.Start();
Application.Run();
 

将有一个调度程序,对不对?在输入线程,确实Dispatcher.CurrentDispatcher返回主线程的调度?或者是什么让一个实例到主线程的调度程序的正确方法?

这可能是,有多个调度程序在WPF应用程序?是否有任何情况下,这将是有意义的创建另一个调度?

解决方案   

WPF应用程序有2个线程(一个   为输入,其他为UI)的

这个说法是不完全正确的。一个WPF应用程序只有一个用于处理所有用户界面交互和用户输入UI线程。还有一个隐藏的线程负责呈现,但通常开发商不处理它。

分派器/螺纹关系是一对一,即,一个分派总是assoticated与一个线程和可用于执行调度给该线程。 Dispatcher.CurrentDispatcher 返回调度当前线程,也就是说,当你调用 Dispatcher.CurrentDispatcher 的工作线程你会得到一个调度员的工作线程。

调度员根据需要创建的,这意味着如果你访问 Dispatcher.CurrentDispatcher 并没有与当前线程相关的调度,将创建一个。

这就是说,调度程序在应用程序的数量总是小于或等于线程在应用程序的数目。

WPF界面控件DevExpress WPF 全新的应用程序主题 v20.2

It is not entirely clear to me how many Dispatchers there are in an application and how they are related to, or referenced from Threads.

As I understand it, a WPF application has 2 threads (one for input, the other for UI) and 1 dispatcher (associated to the UI-Thread). What if I create another thread - let's call it "worker thread" - when I call Dispatcher.CurrentDispatcher on the worker thread, which dispatcher will i get?

Another case: Assume a console application with 2 threads - the main thread, and an input-thread. On the main thread, I first create the input-thread and then i call Application.Run()

Thread thread = new Thread(new ThreadStart(UserInputThreadFunction));
thread.Start();
Application.Run();

There will be one dispatcher, right? On the input-thread, does Dispatcher.CurrentDispatcher return the dispatcher of the main thread? Or what is the proper way of getting an instance to the main thread's dispatcher?

Could it be, that there are more than one dispatcher in a WPF application? Is there any case, it would make sense to create another dispatcher?

解决方案

WPF application has 2 threads (one for input, the other for UI)

This statement is not entirely correct. A WPF application has only one UI thread that handles all the UI interaction and user input. There is also a "hidden" thread responsible for rendering, but normally developers don't deal with it.

Dispatcher / Thread relationship is one to one, i.e. one Dispatcher is always assoticated with one thread and can be used to dispatch execution to that thread. Dispatcher.CurrentDispatcher returns the dispatcher for the current thread, that is, when you call Dispatcher.CurrentDispatcher on a worker thread you get a dispatcher for that working thread.

Dispatchers are created on demand, which means if you access Dispatcher.CurrentDispatcher and there is no dispatcher associated with the current thread, one will be created.

That being said, the number of dispatchers in the application is always less or equal to the number of threads in the application.