Assembly: WindowsBase (in windowsbase.dll)
The Dispatcher maintains a prioritized queue of work items for a specific thread.
When a Dispatcher is created on a thread, it becomes the only Dispatcher that can be associated with the thread, even if the Dispatcher is shut down.
If you attempt to get the CurrentDispatcher for the current thread and a Dispatcher is not associated with the thread a Dispatcher will be created.
If a Dispatcher is shut down, it cannot be restarted.
In WPF, a DispatcherObject can only be accessed by the Dispatcher it is associated with. For example, a background thread cannot update the contents of a Button that is associated with the Dispatcher on the UI thread. In order for the background thread to access the Content property of the Button, the background thread must delegate the work to the Dispatcher associated with the UI thread. This is accomplished by using either Invoke or BeginInvoke. Invoke is synchronous and BeginInvoke is asynchronous. The operation is added to the queue of the Dispatcher at the specified DispatcherPriority.
All of the methods on Dispatcher, with the exception of DisableProcessing, are free-threaded.
Objects that derive from DispatcherObject have thread affinity.
The following example shows how to place an operation onto a Dispatcher. For the full source code of this example, see the Single Threaded Application With Long Running Calculation sample.
First, a delegate is created that accepts no arguments.
Next, BeginInvoke is called. This call to BeginInvoke takes two parameters: the priority, which is set to Normal, and the callback, which is passed in through an instance of the delegate nextPrimeDelegate.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.