WPF Dispatcher VS Winform UI Thread Control Invoke

1.3k Views Asked by At

I have one query, in Winform (UI Thread) control Invoke is there to handle cross thread issue, then why Dispatcher is introduced in WPF? What are the other advantages of Dispatcher?

Please help me understanding this.

1

There are 1 best solutions below

0
On BEST ANSWER

The main reason Dispatcher was introduced in WPF is that WPF isn't WinForms and WinForms class members aren't relevant to WPF objects. They had to do something.

Could Microsoft have implemented WPF exactly the same way as they did WinForms? Sure. But WPF is a fundamentally different kind of API, and it makes sense that they would take the opportunity to redesign the paradigm that deals with the thread affinity that naturally occurs when writing any Windows software, managed or otherwise.

Note that WPF, and the Dispatcher in particular, are higher-level abstractions than WinForms and its Invoke() method. The application has more control over the Dispatcher than a WinForms program would over Invoke(). The Dispatcher supports different priorities, and even supports exceptions for DispatcherObjects that can safely be used in different threads (see Freezable).

At the end of the day, WPF's Dispatcher is doing much the same job as WinForm's Invoke() method. It's just a bit shinier and offers more nuanced mechanisms for accomplishing the same fundamental goal.