Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the UI thread's Dispatcher?

Is there any way to get the UI thread's Dispatcher when you have no reference to any UI elements?

like image 759
Peter Avatar asked Apr 18 '10 16:04

Peter


People also ask

What is application current dispatcher?

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.

How do you use a dispatcher?

If you're in the main window you can use: Dispatcher. BeginInvoke(... Use Invoke if you want the current thread to wait until the UI thread has processed the dispatch code or BeginInvoke if you want current thread to continue without waiting for operation to complete on UI thread.

What is WPF dispatcher?

WPF Dispatcher is associated with the UI thread. The UI thread queues methods call inside the Dispatcher object. Whenever your changes the screen or any event executes, or call a method in the code-behind all this happen in the UI thread and UI thread queue the called method into the Dispatcher queue.

What is a dispatcher thread?

A Dispatcher is responsible for managing the work for a thread. The UI thread is the thread that renders the UI. The UI thread queues work items inside an object called a Dispatcher. The Dispatcher selects work items on a priority basis and runs each one to completion.


1 Answers

You can grab the UI Dispatcher from the static application instance: Application.Current.Dispatcher

You may want to check Application.Current for null first, as it can be cleared during a shutdown sequence.

like image 133
Abe Heidebrecht Avatar answered Nov 01 '22 12:11

Abe Heidebrecht