Dispatcher to Thread relationships in WPF

前端 未结 3 565
温柔的废话
温柔的废话 2020-12-08 07:23

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 ap

3条回答
  •  执念已碎
    2020-12-08 08:26

    A dispatcher is always associated with a thread and a thread can have at most one dispatcher running at the same time. A thread does not need to have a dispatcher.

    By default there is only one Dispatcher - For the UI. Sometimes it makes sense to have other dispatchers, other time it does not. A dispatching thread needs to block in the Dispatcher.Run() method in order to process invokes to the dispatcher. A thread such as your console input thread will not be availible to process invokes.

提交回复
热议问题