Dispatcher.Invoke Dispatcher.Invoke Dispatcher.Invoke Dispatcher.Invoke Method

定义

在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate synchronously on the thread the Dispatcher is associated with.

重载

Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[]) Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[]) Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[]) Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

Invoke(DispatcherPriority, TimeSpan, Delegate, Object) Invoke(DispatcherPriority, TimeSpan, Delegate, Object) Invoke(DispatcherPriority, TimeSpan, Delegate, Object) Invoke(DispatcherPriority, TimeSpan, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.

Invoke(DispatcherPriority, Delegate, Object, Object[]) Invoke(DispatcherPriority, Delegate, Object, Object[]) Invoke(DispatcherPriority, Delegate, Object, Object[]) Invoke(DispatcherPriority, Delegate, Object, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan) Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan) Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

Invoke(DispatcherPriority, TimeSpan, Delegate) Invoke(DispatcherPriority, TimeSpan, Delegate) Invoke(DispatcherPriority, TimeSpan, Delegate) Invoke(DispatcherPriority, TimeSpan, Delegate)

按指定的优先级并使用指定的超时值在创建 Dispatcher 的线程上同步执行指定的委托。Executes the specified delegate synchronously at the specified priority and with the specified time-out value on the thread the Dispatcher was created.

Invoke(DispatcherPriority, Delegate, Object) Invoke(DispatcherPriority, Delegate, Object) Invoke(DispatcherPriority, Delegate, Object) Invoke(DispatcherPriority, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.

Invoke(Delegate, TimeSpan, DispatcherPriority, Object[]) Invoke(Delegate, TimeSpan, DispatcherPriority, Object[]) Invoke(Delegate, TimeSpan, DispatcherPriority, Object[]) Invoke(Delegate, TimeSpan, DispatcherPriority, Object[])

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。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.

Invoke(Delegate, TimeSpan, Object[]) Invoke(Delegate, TimeSpan, Object[]) Invoke(Delegate, TimeSpan, Object[]) Invoke(Delegate, TimeSpan, Object[])

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。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.

Invoke(Action, DispatcherPriority, CancellationToken) Invoke(Action, DispatcherPriority, CancellationToken) Invoke(Action, DispatcherPriority, CancellationToken)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

Invoke(DispatcherPriority, Delegate) Invoke(DispatcherPriority, Delegate) Invoke(DispatcherPriority, Delegate) Invoke(DispatcherPriority, Delegate)

按指定的优先级在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate synchronously at the specified priority on the thread on which the Dispatcher is associated with.

Invoke(Delegate, Object[]) Invoke(Delegate, Object[]) Invoke(Delegate, Object[]) Invoke(Delegate, Object[])

用与 Dispatcher 关联的线程上的指定参数同步执行指定委托。Executes the specified delegate with the specified arguments synchronously on the thread the Dispatcher is associated with.

Invoke(Action, DispatcherPriority) Invoke(Action, DispatcherPriority) Invoke(Action, DispatcherPriority) Invoke(Action, DispatcherPriority)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

Invoke(Action) Invoke(Action) Invoke(Action) Invoke(Action)

在与 Action 关联的线程上同步执行指定的 DispatcherExecutes the specified Action synchronously on the thread the Dispatcher is associated with.

Invoke(Delegate, DispatcherPriority, Object[]) Invoke(Delegate, DispatcherPriority, Object[]) Invoke(Delegate, DispatcherPriority, Object[]) Invoke(Delegate, DispatcherPriority, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

Invoke<TResult>(Func<TResult>) Invoke<TResult>(Func<TResult>) Invoke<TResult>(Func<TResult>) Invoke<TResult>(Func<TResult>)

在与 Func<TResult> 关联的线程上同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously on the thread the Dispatcher is associated with.

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

示例

以下示例将放到上的一个委托DispatcherNormal使用InvokeThe 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));
}
' Places the delegate onto the UI Thread's Dispatcher
Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
	' Place delegate on the Dispatcher.
	Me.Dispatcher.Invoke(DispatcherPriority.Normal, New TimerDispatcherDelegate(AddressOf TimerWorkItem))
End Sub

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[]) Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[]) Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[]) Invoke(DispatcherPriority, TimeSpan, Delegate, Object, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

public:
 System::Object ^ Invoke(System::Windows::Threading::DispatcherPriority priority, TimeSpan timeout, Delegate ^ method, System::Object ^ arg, ... cli::array <System::Object ^> ^ args);
[System.ComponentModel.Browsable(false)]
public object Invoke (System.Windows.Threading.DispatcherPriority priority, TimeSpan timeout, Delegate method, object arg, params object[] args);
member this.Invoke : System.Windows.Threading.DispatcherPriority * TimeSpan * Delegate * obj * obj[] -> obj
Public Function Invoke (priority As DispatcherPriority, timeout As TimeSpan, method As Delegate, arg As Object, ParamArray args As Object()) As Object

参数

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

用于等待操作完成的最长时间。The maximum time to wait for the operation to finish.

method
Delegate Delegate Delegate Delegate

对采用多个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

arg
Object Object Object Object

作为参数传递到指定方法中的对象。An object to pass as an argument to the specified method.

args
Object[]

作为指定方法的参数传递的对象数组。An array of objects to pass as arguments to the specified method.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

异常

注解

Arg 可以是null如果不需要参数。Arg can be null if an argument is not needed.

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(DispatcherPriority, TimeSpan, Delegate, Object) Invoke(DispatcherPriority, TimeSpan, Delegate, Object) Invoke(DispatcherPriority, TimeSpan, Delegate, Object) Invoke(DispatcherPriority, TimeSpan, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.

public:
 System::Object ^ Invoke(System::Windows::Threading::DispatcherPriority priority, TimeSpan timeout, Delegate ^ method, System::Object ^ arg);
[System.ComponentModel.Browsable(false)]
public object Invoke (System.Windows.Threading.DispatcherPriority priority, TimeSpan timeout, Delegate method, object arg);
member this.Invoke : System.Windows.Threading.DispatcherPriority * TimeSpan * Delegate * obj -> obj
Public Function Invoke (priority As DispatcherPriority, timeout As TimeSpan, method As Delegate, arg As Object) As Object

参数

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

用于等待操作完成的最长时间。The maximum time to wait for the operation to finish.

method
Delegate Delegate Delegate Delegate

对采用多个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

arg
Object Object Object Object

作为参数传递到给定方法中的对象。An object to pass as an argument to the given method. 如果不需要自变量,则可以为 nullThis can be null if no arguments are needed.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

异常

priority 不是有效的优先级。priority is not a valid priority.

注解

Arg 可以是null如果不需要参数Arg can be null if an argument is not needed

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(DispatcherPriority, Delegate, Object, Object[]) Invoke(DispatcherPriority, Delegate, Object, Object[]) Invoke(DispatcherPriority, Delegate, Object, Object[]) Invoke(DispatcherPriority, Delegate, Object, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

public:
 System::Object ^ Invoke(System::Windows::Threading::DispatcherPriority priority, Delegate ^ method, System::Object ^ arg, ... cli::array <System::Object ^> ^ args);
[System.ComponentModel.Browsable(false)]
public object Invoke (System.Windows.Threading.DispatcherPriority priority, Delegate method, object arg, params object[] args);
member this.Invoke : System.Windows.Threading.DispatcherPriority * Delegate * obj * obj[] -> obj
Public Function Invoke (priority As DispatcherPriority, method As Delegate, arg As Object, ParamArray args As Object()) As Object

参数

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

method
Delegate Delegate Delegate Delegate

对采用多个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

arg
Object Object Object Object

作为参数传递到给定方法中的对象。An object to pass as an argument to the given method.

args
Object[]

作为给定方法的自变量传递的对象数组。An array of objects to pass as arguments to the given method.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

异常

priority 不是有效的优先级。priority is not a valid priority.

注解

Arg 可以是null如果不需要参数Arg can be null if an argument is not needed

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan) Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan) Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

public:
 void Invoke(Action ^ callback, System::Windows::Threading::DispatcherPriority priority, System::Threading::CancellationToken cancellationToken, TimeSpan timeout);
public void Invoke (Action callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken, TimeSpan timeout);
member this.Invoke : Action * System.Windows.Threading.DispatcherPriority * System.Threading.CancellationToken * TimeSpan -> unit

参数

callback
Action Action Action Action

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

决定相对于 Dispatcher 中的其他挂起操作调用回调的顺序的优先级。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

指示是否取消操作的对象。An object that indicates whether to cancel the action.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

等待操作启动的最长时间。The minimum amount of time to wait for the operation to start.

Invoke(DispatcherPriority, TimeSpan, Delegate) Invoke(DispatcherPriority, TimeSpan, Delegate) Invoke(DispatcherPriority, TimeSpan, Delegate) Invoke(DispatcherPriority, TimeSpan, Delegate)

按指定的优先级并使用指定的超时值在创建 Dispatcher 的线程上同步执行指定的委托。Executes the specified delegate synchronously at the specified priority and with the specified time-out value on the thread the Dispatcher was created.

public:
 System::Object ^ Invoke(System::Windows::Threading::DispatcherPriority priority, TimeSpan timeout, Delegate ^ method);
[System.ComponentModel.Browsable(false)]
public object Invoke (System.Windows.Threading.DispatcherPriority priority, TimeSpan timeout, Delegate method);
member this.Invoke : System.Windows.Threading.DispatcherPriority * TimeSpan * Delegate -> obj
Public Function Invoke (priority As DispatcherPriority, timeout As TimeSpan, method As Delegate) As Object

参数

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

用于等待操作完成的最长时间。The maximum time to wait for the operation to finish.

method
Delegate Delegate Delegate Delegate

对不采用任何参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。The delegate to a method that takes no arguments, which is pushed onto the Dispatcher event queue.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(DispatcherPriority, Delegate, Object) Invoke(DispatcherPriority, Delegate, Object) Invoke(DispatcherPriority, Delegate, Object) Invoke(DispatcherPriority, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified argument synchronously on the thread the Dispatcher is associated with.

public:
 System::Object ^ Invoke(System::Windows::Threading::DispatcherPriority priority, Delegate ^ method, System::Object ^ arg);
[System.ComponentModel.Browsable(false)]
public object Invoke (System.Windows.Threading.DispatcherPriority priority, Delegate method, object arg);
member this.Invoke : System.Windows.Threading.DispatcherPriority * Delegate * obj -> obj
Public Function Invoke (priority As DispatcherPriority, method As Delegate, arg As Object) As Object

参数

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

method
Delegate Delegate Delegate Delegate

对采用一个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes one argument, which is pushed onto the Dispatcher event queue.

arg
Object Object Object Object

作为参数传递到给定方法中的对象。An object to pass as an argument to the given method.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

异常

priority 不是有效的优先级。priority is not a valid priority.

注解

Arg 可以是null如果不需要参数Arg can be null if an argument is not needed

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(Delegate, TimeSpan, DispatcherPriority, Object[]) Invoke(Delegate, TimeSpan, DispatcherPriority, Object[]) Invoke(Delegate, TimeSpan, DispatcherPriority, Object[]) Invoke(Delegate, TimeSpan, DispatcherPriority, Object[])

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。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:
 System::Object ^ Invoke(Delegate ^ method, TimeSpan timeout, System::Windows::Threading::DispatcherPriority priority, ... cli::array <System::Object ^> ^ args);
public object Invoke (Delegate method, TimeSpan timeout, System.Windows.Threading.DispatcherPriority priority, params object[] args);
member this.Invoke : Delegate * TimeSpan * System.Windows.Threading.DispatcherPriority * obj[] -> obj
Public Function Invoke (method As Delegate, timeout As TimeSpan, priority As DispatcherPriority, ParamArray args As Object()) As Object

参数

method
Delegate Delegate Delegate Delegate

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

等待操作完成的最长时间。The maximum amount of time to wait for the operation to complete.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

args
Object[]

作为给定方法的自变量传递的对象数组。An array of objects to pass as arguments to the given method. 可以为 nullCan be null.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(Delegate, TimeSpan, Object[]) Invoke(Delegate, TimeSpan, Object[]) Invoke(Delegate, TimeSpan, Object[]) Invoke(Delegate, TimeSpan, Object[])

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。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:
 System::Object ^ Invoke(Delegate ^ method, TimeSpan timeout, ... cli::array <System::Object ^> ^ args);
public object Invoke (Delegate method, TimeSpan timeout, params object[] args);
member this.Invoke : Delegate * TimeSpan * obj[] -> obj
Public Function Invoke (method As Delegate, timeout As TimeSpan, ParamArray args As Object()) As Object

参数

method
Delegate Delegate Delegate Delegate

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

等待操作完成的最长时间。The maximum amount of time to wait for the operation to complete.

args
Object[]

作为给定方法的自变量传递的对象数组。An array of objects to pass as arguments to the given method. 可以为 nullCan be null.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(Action, DispatcherPriority, CancellationToken) Invoke(Action, DispatcherPriority, CancellationToken) Invoke(Action, DispatcherPriority, CancellationToken)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

public:
 void Invoke(Action ^ callback, System::Windows::Threading::DispatcherPriority priority, System::Threading::CancellationToken cancellationToken);
public void Invoke (Action callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken);
member this.Invoke : Action * System.Windows.Threading.DispatcherPriority * System.Threading.CancellationToken -> unit

参数

callback
Action Action Action Action

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

决定相对于 Dispatcher 中的其他挂起操作调用回调的顺序的优先级。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

指示是否取消操作的对象。An object that indicates whether to cancel the action.

Invoke(DispatcherPriority, Delegate) Invoke(DispatcherPriority, Delegate) Invoke(DispatcherPriority, Delegate) Invoke(DispatcherPriority, Delegate)

按指定的优先级在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate synchronously at the specified priority on the thread on which the Dispatcher is associated with.

public:
 System::Object ^ Invoke(System::Windows::Threading::DispatcherPriority priority, Delegate ^ method);
[System.ComponentModel.Browsable(false)]
public object Invoke (System.Windows.Threading.DispatcherPriority priority, Delegate method);
member this.Invoke : System.Windows.Threading.DispatcherPriority * Delegate -> obj
Public Function Invoke (priority As DispatcherPriority, method As Delegate) As Object

参数

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

method
Delegate Delegate Delegate Delegate

对不采用任何参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes no arguments, which is pushed onto the Dispatcher event queue.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

异常

priority 不是有效的优先级。priority is not a valid priority.

示例

以下示例将放到上的一个委托DispatcherNormal使用InvokeThe 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));
}
' Places the delegate onto the UI Thread's Dispatcher
Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
	' Place delegate on the Dispatcher.
	Me.Dispatcher.Invoke(DispatcherPriority.Normal, New TimerDispatcherDelegate(AddressOf TimerWorkItem))
End Sub

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(Delegate, Object[]) Invoke(Delegate, Object[]) Invoke(Delegate, Object[]) Invoke(Delegate, Object[])

用与 Dispatcher 关联的线程上的指定参数同步执行指定委托。Executes the specified delegate with the specified arguments synchronously on the thread the Dispatcher is associated with.

public:
 System::Object ^ Invoke(Delegate ^ method, ... cli::array <System::Object ^> ^ args);
public object Invoke (Delegate method, params object[] args);
member this.Invoke : Delegate * obj[] -> obj
Public Function Invoke (method As Delegate, ParamArray args As Object()) As Object

参数

method
Delegate Delegate Delegate Delegate

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

args
Object[]

作为给定方法的自变量传递的对象数组。An array of objects to pass as arguments to the given method. 可以为 nullCan be null.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke(Action, DispatcherPriority) Invoke(Action, DispatcherPriority) Invoke(Action, DispatcherPriority) Invoke(Action, DispatcherPriority)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

public:
 void Invoke(Action ^ callback, System::Windows::Threading::DispatcherPriority priority);
public void Invoke (Action callback, System.Windows.Threading.DispatcherPriority priority);
member this.Invoke : Action * System.Windows.Threading.DispatcherPriority -> unit
Public Sub Invoke (callback As Action, priority As DispatcherPriority)

参数

callback
Action Action Action Action

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

决定相对于 Dispatcher 中的其他挂起操作调用回调的顺序的优先级。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

Invoke(Action) Invoke(Action) Invoke(Action) Invoke(Action)

在与 Action 关联的线程上同步执行指定的 DispatcherExecutes the specified Action synchronously on the thread the Dispatcher is associated with.

public:
 void Invoke(Action ^ callback);
public void Invoke (Action callback);
member this.Invoke : Action -> unit
Public Sub Invoke (callback As Action)

参数

callback
Action Action Action Action

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

Invoke(Delegate, DispatcherPriority, Object[]) Invoke(Delegate, DispatcherPriority, Object[]) Invoke(Delegate, DispatcherPriority, Object[]) Invoke(Delegate, DispatcherPriority, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。Executes the specified delegate at the specified priority with the specified arguments synchronously on the thread the Dispatcher is associated with.

public:
 System::Object ^ Invoke(Delegate ^ method, System::Windows::Threading::DispatcherPriority priority, ... cli::array <System::Object ^> ^ args);
public object Invoke (Delegate method, System.Windows.Threading.DispatcherPriority priority, params object[] args);
member this.Invoke : Delegate * System.Windows.Threading.DispatcherPriority * obj[] -> obj
Public Function Invoke (method As Delegate, priority As DispatcherPriority, ParamArray args As Object()) As Object

参数

method
Delegate Delegate Delegate Delegate

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

指定调用方法的优先级,与 Dispatcher 事件队列中的其他挂起操作相关。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

args
Object[]

作为给定方法的自变量传递的对象数组。An array of objects to pass as arguments to the given method. 可以为 nullCan be null.

返回

正在被调用的委托的返回值,如果该委托没有返回值,则为 nullThe return value from the delegate being invoked or null if the delegate has no return value.

注解

在中WPFWPF,只有创建的线程DispatcherObject才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 UI 线程运行的后台线程不能更新的内容ButtonUI 线程上创建。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. 为了使后台线程将访问的内容属性的Button,后台线程必须将工作委托给Dispatcher与 UI 线程关联。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. 这通过使用实现InvokeBeginInvokeThis is accomplished by using either Invoke or BeginInvoke. Invoke 是同步和BeginInvoke是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 该操作将添加到的事件队列Dispatcher在指定DispatcherPriorityThe operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

Invoke 是一项同步操作;因此,控件不会返回对调用对象直到回调返回后。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

Invoke<TResult>(Func<TResult>) Invoke<TResult>(Func<TResult>) Invoke<TResult>(Func<TResult>) Invoke<TResult>(Func<TResult>)

在与 Func<TResult> 关联的线程上同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously on the thread the Dispatcher is associated with.

public:
generic <typename TResult>
 TResult Invoke(Func<TResult> ^ callback);
public TResult Invoke<TResult> (Func<TResult> callback);
member this.Invoke : Func<'Result> -> 'Result
Public Function Invoke(Of TResult) (callback As Func(Of TResult)) As TResult

类型参数

TResult

指定委托的返回值类型。The return value type of the specified delegate.

参数

callback
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

返回

TResult TResult TResult TResult

注解

返回的值callbackThe value returned by callback.

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

public:
generic <typename TResult>
 TResult Invoke(Func<TResult> ^ callback, System::Windows::Threading::DispatcherPriority priority);
public TResult Invoke<TResult> (Func<TResult> callback, System.Windows.Threading.DispatcherPriority priority);
member this.Invoke : Func<'Result> * System.Windows.Threading.DispatcherPriority -> 'Result
Public Function Invoke(Of TResult) (callback As Func(Of TResult), priority As DispatcherPriority) As TResult

类型参数

TResult

指定委托的返回值类型。The return value type of the specified delegate.

参数

callback
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

决定相对于 Dispatcher 中的其他挂起操作调用回调的顺序的优先级。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

返回

TResult TResult TResult TResult

注解

返回的值callbackThe value returned by callback.

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

public:
generic <typename TResult>
 TResult Invoke(Func<TResult> ^ callback, System::Windows::Threading::DispatcherPriority priority, System::Threading::CancellationToken cancellationToken);
public TResult Invoke<TResult> (Func<TResult> callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken);
member this.Invoke : Func<'Result> * System.Windows.Threading.DispatcherPriority * System.Threading.CancellationToken -> 'Result

类型参数

TResult

指定委托的返回值类型。The return value type of the specified delegate.

参数

callback
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

决定相对于 Dispatcher 中的其他挂起操作调用回调的顺序的优先级。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

指示是否取消操作的对象。An object that indicates whether to cancel the operation.

返回

TResult TResult TResult TResult

注解

返回的值callbackThe value returned by callback.

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

public:
generic <typename TResult>
 TResult Invoke(Func<TResult> ^ callback, System::Windows::Threading::DispatcherPriority priority, System::Threading::CancellationToken cancellationToken, TimeSpan timeout);
public TResult Invoke<TResult> (Func<TResult> callback, System.Windows.Threading.DispatcherPriority priority, System.Threading.CancellationToken cancellationToken, TimeSpan timeout);
member this.Invoke : Func<'Result> * System.Windows.Threading.DispatcherPriority * System.Threading.CancellationToken * TimeSpan -> 'Result

类型参数

TResult

指定委托的返回值类型。The return value type of the specified delegate.

参数

callback
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

要通过调度程序调用的委托。A delegate to invoke through the dispatcher.

priority
DispatcherPriority DispatcherPriority DispatcherPriority DispatcherPriority

决定相对于 Dispatcher 中的其他挂起操作调用回调的顺序的优先级。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

指示是否取消操作的对象。An object that indicates whether to cancel the operation.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

等待操作启动的最长时间。The minimum amount of time to wait for the operation to start.

返回

TResult TResult TResult TResult

注解

返回的值callbackThe value returned by callback.

适用于