Is there any documentation as to the exact meanings of each of the DispatcherPriority enumeration values, in relation to a WPF application.
In particular, is there any practical difference between Background
/ ContextIdle
/ ApplicationIdle
? I've found myself using each of these in various parts of my code and would like to standardise on one value.
A typical usage would be in a data bound TreeView control. When setting an item as selected (in the ViewModel), I want to first expand all of its parent items (again in the ViewModel), then wait for them to be fully rendered (in the View) before actually setting the selected property.
The Dispatcher class is used to perform work on its attached thread. It has a queue of work items and it is in charge of executing the work items on the dispatcher thread.
Invoke(Action, DispatcherPriority) Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with. Invoke(Action) Executes the specified Action synchronously on the thread the Dispatcher is associated with.
BeginInvoke(DispatcherPriority, Delegate) Executes the specified delegate asynchronously at the specified priority on the thread the Dispatcher is associated with. BeginInvoke(Delegate, DispatcherPriority, Object[])
CurrentDispatcher may create a new instance of Dispatcher depending on the thread from which it was called. That is correct, the Application. Current. Dispatcher is an instance property of the application which is assigned upon construction to be the dispatcher of the current thread.
Best way to understand how it is actually working is to see source code of it.
.Net Framework source code is available at https://referencesource.microsoft.com/
You can get answers for your question after checking out and understanding this code https://referencesource.microsoft.com/#WindowsBase/Base/System/Windows/Threading/Dispatcher.cs,ad208569500b2a1d
My quick understanding: there is a lot of priorities is just to give oportunity to specify priority of operation more precise if it will be needed by your code. There is no hidden events/states to perform operations of specific priorities. Alghoritm will take task with top priority and invoke it, and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With