Invoke Method

Dispatcher.Invoke Method

 

Executes the specified delegate synchronously on the thread the Dispatcher is associated with.

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

NameDescription
System_CAPS_pubmethodInvoke(Action)

Executes the specified Action synchronously on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(Action, DispatcherPriority)

Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(Action, DispatcherPriority, CancellationToken)

Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(Action, DispatcherPriority, CancellationToken, TimeSpan)

Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(Delegate, DispatcherPriority, Object[])

Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(Delegate, Object[])

Executes the specified delegate with the specified arguments synchronously on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(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.

System_CAPS_pubmethodInvoke(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.

System_CAPS_pubmethodInvoke(DispatcherPriority, Delegate)

Executes the specified delegate synchronously at the specified priority on the thread on which the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(DispatcherPriority, Delegate, Object)

Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke(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.

System_CAPS_pubmethodInvoke(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.

System_CAPS_pubmethodInvoke(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.

System_CAPS_pubmethodInvoke(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.

System_CAPS_pubmethodInvoke<TResult>(Func<TResult>)

Executes the specified Func<TResult> synchronously on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke<TResult>(Func<TResult>, DispatcherPriority)

Executes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke<TResult>(Func<TResult>, DispatcherPriority, CancellationToken)

Executes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

System_CAPS_pubmethodInvoke<TResult>(Func<TResult>, DispatcherPriority, CancellationToken, TimeSpan)

Executes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

In WPF, only the thread that created a DispatcherObject may access that object. For example, a background thread that is spun off from the main UI thread cannot update the contents of a Button that was created 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 event queue of the Dispatcher at the specified DispatcherPriority.

Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

The following example places a delegate onto a Dispatcher at Normal using Invoke.

// Places the delegate onto the UI Thread's Dispatcher
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
    // Place delegate on the Dispatcher.
    this.Dispatcher.Invoke(DispatcherPriority.Normal,
        new TimerDispatcherDelegate(TimerWorkItem));
}
Return to top
Show:
© 2016 Microsoft