Export (0) Print
Expand All

Dispatcher Class

Provides services for managing the queue of work items for a thread.

System.Object
  System.Windows.Threading.Dispatcher

Namespace:  System.Windows.Threading
Assembly:  WindowsBase (in WindowsBase.dll)

[<Sealed>]
type Dispatcher =  class end

The Dispatcher type exposes the following members.

  NameDescription
Public propertyStatic memberCurrentDispatcherGets the Dispatcher for the thread currently executing and creates a new Dispatcher if one is not already associated with the thread.
Public propertyHasShutdownFinishedDetermines whether the Dispatcher has finished shutting down.
Public propertyHasShutdownStartedDetermines whether the Dispatcher is shutting down.
Public propertyHooksGets the collection of hooks that provide additional event information about the Dispatcher.
Public propertyThreadGets the thread this Dispatcher is associated with.
Top

  NameDescription
Public methodBeginInvoke(Delegate, Object[])Executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher was created on.
Public methodBeginInvoke(DispatcherPriority, Delegate)Executes the specified delegate asynchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodBeginInvoke(Delegate, DispatcherPriority, Object[])Executes the specified delegate asynchronously with the specified arguments, at the specified priority, on the thread that the Dispatcher was created on.
Public methodBeginInvoke(DispatcherPriority, Delegate, Object)Executes the specified delegate asynchronously at the specified priority and with the specified argument on the thread the Dispatcher is associated with.
Public methodBeginInvoke(DispatcherPriority, Delegate, Object, Object[])Executes the specified delegate asynchronously at the specified priority and with the specified array of arguments on the thread the Dispatcher is associated with.
Public methodBeginInvokeShutdownInitiates shutdown of the Dispatcher asynchronously.
Public methodCheckAccessDetermines whether the calling thread is the thread associated with this Dispatcher.
Public methodDisableProcessingDisables processing of the Dispatcher queue.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberExitAllFramesRequests that all frames exit, including nested frames.
Public methodStatic memberFromThreadGets the Dispatcher for the specified thread.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInvoke(Action)Executes the specified Action synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(Action, DispatcherPriority)Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvoke(Delegate, Object[])Executes the specified delegate with the specified arguments synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(DispatcherPriority, Delegate)Executes the specified delegate synchronously at the specified priority on the thread on which the Dispatcher is associated with.
Public methodInvoke(Action, DispatcherPriority, CancellationToken)Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvoke(Delegate, TimeSpan, Object[])Executes the specified delegate within the designated time span at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(Delegate, DispatcherPriority, Object[])Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(DispatcherPriority, Delegate, Object)Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(DispatcherPriority, TimeSpan, Delegate)Executes the specified delegate synchronously at the specified priority and with the specified time-out value on the thread the Dispatcher was created.
Public methodInvoke(Action, DispatcherPriority, CancellationToken, TimeSpan)Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvoke(Delegate, TimeSpan, DispatcherPriority, Object[])Executes the specified delegate within the designated time span at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(DispatcherPriority, Delegate, Object, Object[])Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(DispatcherPriority, TimeSpan, Delegate, Object)Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[])Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(TResult)(Func(TResult))Executes the specified Func(TResult) synchronously on the thread the Dispatcher is associated with.
Public methodInvoke(TResult)(Func(TResult), DispatcherPriority)Executes the specified Func(TResult) synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvoke(TResult)(Func(TResult), DispatcherPriority, CancellationToken)Executes the specified Func(TResult) synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvoke(TResult)(Func(TResult), DispatcherPriority, CancellationToken, TimeSpan)Executes the specified Func(TResult) synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvokeAsync(Action)Executes the specified Action asynchronously on the thread the Dispatcher is associated with.
Public methodInvokeAsync(Action, DispatcherPriority)Executes the specified Action asynchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvokeAsync(Action, DispatcherPriority, CancellationToken)Executes the specified Action asynchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvokeAsync(TResult)(Func(TResult))Executes the specified Func(TResult) asynchronously on the thread the Dispatcher is associated with.
Public methodInvokeAsync(TResult)(Func(TResult), DispatcherPriority)Executes the specified Func(TResult) asynchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvokeAsync(TResult)(Func(TResult), DispatcherPriority, CancellationToken)Executes the specified Func(TResult) synchronously at the specified priority on the thread the Dispatcher is associated with.
Public methodInvokeShutdownInitiates the shutdown process of the Dispatcher synchronously.
Public methodStatic memberPushFrameEnters an execute loop.
Public methodStatic memberRunPushes the main execution frame on the event queue of the Dispatcher.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberValidatePriorityDetermines whether the specified DispatcherPriority is a valid priority.
Public methodVerifyAccessDetermines whether the calling thread has access to this Dispatcher.
Public methodStatic memberYield()Creates an awaitable object that asynchronously yields control back to the current dispatcher and provides an opportunity for the dispatcher to process other events.
Public methodStatic memberYield(DispatcherPriority)Creates an awaitable object that asynchronously yields control back to the current dispatcher and provides an opportunity for the dispatcher to process other events. The work that occurs when control returns to the code awaiting the result of this method is scheduled with the specified priority.
Top

  NameDescription
Public eventShutdownFinishedOccurs when the Dispatcher finishes shutting down.
Public eventShutdownStartedOccurs when the Dispatcher begins to shut down.
Public eventUnhandledExceptionOccurs when a thread exception is thrown and uncaught during execution of a delegate by way of Invoke or BeginInvoke.
Public eventUnhandledExceptionFilterOccurs when a thread exception is thrown and uncaught during execution of a delegate by way of Invoke or BeginInvoke when in the filter stage.
Top

  NameDescription
Public Extension MethodBeginInvoke(Action)Overloaded. Executes the specified delegate asynchronously with normal priority on the thread that the specified Dispatcher was created on. (Defined by DispatcherExtensions.)
Public Extension MethodBeginInvoke(Action, DispatcherPriority)Overloaded. Executes the specified delegate asynchronously with the specified priority on the thread that the specified Dispatcher was created on. (Defined by DispatcherExtensions.)
Public Extension MethodInvoke(Action)Overloaded. Executes the specified delegate synchronously with normal priority on the thread that the specified Dispatcher was created on. (Defined by DispatcherExtensions.)
Public Extension MethodInvoke(Action, TimeSpan)Overloaded. Executes the specified delegate synchronously on the thread that the specified Dispatcher was created on, and stops execution after the specified time-out period. (Defined by DispatcherExtensions.)
Public Extension MethodInvoke(Action, DispatcherPriority)Overloaded. Executes the specified delegate synchronously with the specified priority on the thread that the specified Dispatcher was created on. (Defined by DispatcherExtensions.)
Public Extension MethodInvoke(Action, TimeSpan, DispatcherPriority)Overloaded. Executes the specified delegate synchronously with the specified priority on the thread that the specified Dispatcher was created on, and stops execution after the specified time-out period. (Defined by DispatcherExtensions.)
Top

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. A Dispatcher is also created when you create a DispatcherObject. If you create a Dispatcher on a background thread, be sure to shut down the dispatcher before exiting the thread.

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 BeginInvokeInvoke is synchronous and BeginInvoke is asynchronous. The operation is added to the queue of the Dispatcher at the specified DispatcherPriority.

If BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

All of the methods on Dispatcher, with the exception of DisableProcessing, are free-threaded.

Objects that derive from DispatcherObject have thread affinity.

Objects that derive from Freezable are free-threaded when they are frozen. For more information, see Freezable Objects Overview.

The following example shows how to place an operation onto a Dispatcher. 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.

No code example is currently available or this language may not be supported.

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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft