Updated: August 2011
Provides services for managing the queue of work items for a thread.
Assembly: WindowsBase (in WindowsBase.dll)
The maintains a prioritized queue of work items for a specific thread.
When a is created on a thread, it becomes the only that can be associated with the thread, even if the is shut down.
If you attempt to get the CurrentDispatcher for the current thread and a is not associated with the thread, a will be created. A is also created when you create a DispatcherObject. If you create a on a background thread, be sure to shut down the dispatcher before exiting the thread.
If a is shut down, it cannot be restarted.
In WPF, a DispatcherObject can only be accessed by the it is associated with. For example, a background thread cannot update the contents of a Button that is associated with the 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 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 at the specified DispatcherPriority.
All of the methods on , 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 . For the full source code of this example, see Single-Threaded Application with Long-Running Calculation Sample.
First, a delegate is created that accepts no arguments.
Next, BeginInvoke(DispatcherPriority, Delegate) is called. This call to BeginInvoke(DispatcherPriority, Delegate) takes two parameters: the priority, which is set to DispatcherPriority::Normal, and the callback, which is passed in through an instance of the delegate NextPrimeDelegate.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Added remarks about shutting down the on a background thread.
Added new members: BeginInvoke(Delegate, array<Object>), BeginInvoke(Delegate, DispatcherPriority, array<Object>), Invoke(Delegate, array<Object>), Invoke(Delegate, TimeSpan, array<Object>), Invoke(Delegate, TimeSpan, DispatcherPriority, array<Object>), Invoke(Delegate, DispatcherPriority, array<Object>)
SP1 feature change.