Dispatcher.Invoke 方法

定义

在与 Dispatcher 关联的线程上同步执行指定的委托。

重载

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

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

Invoke(DispatcherPriority, TimeSpan, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

Invoke(DispatcherPriority, TimeSpan, Delegate)

按指定的优先级并使用指定的超时值在创建 Dispatcher 的线程上同步执行指定的委托。

Invoke(DispatcherPriority, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。

Invoke(Delegate, TimeSpan, Object[])

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。

Invoke(Action, DispatcherPriority, CancellationToken)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

Invoke(DispatcherPriority, Delegate)

在与之关联的线程 Dispatcher 上以指定的优先级同步执行指定的委托。

Invoke(Delegate, Object[])

用与 Dispatcher 关联的线程上的指定参数同步执行指定委托。

Invoke(Action, DispatcherPriority)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

Invoke(Action)

在与 Action 关联的线程上同步执行指定的 Dispatcher

Invoke(Delegate, DispatcherPriority, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

Invoke<TResult>(Func<TResult>)

在与 Func<TResult> 关联的线程上同步执行指定的 Dispatcher

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

示例

以下示例将委托置于Dispatcher使用Invoke位置Normal

// 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

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

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

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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);
[<System.ComponentModel.Browsable(false)>]
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

相对于调用指定方法的事件队列中的其他 Dispatcher 挂起操作的优先级。

timeout
TimeSpan

等待操作启动的最大时间量。 操作启动后,将在此方法返回之前完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

method
Delegate

对采用多个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

arg
Object

作为参数传递到指定方法中的对象。

args
Object[]

作为指定方法的参数传递的对象数组。

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

属性

例外

priority 等于 Inactive

priority 不是有效的 DispatcherPriority

methodnull

timeout 是除 -1 以外的负数,此方法在线程之间调用。

注解

arg 如果不需要参数,则可以 null

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(DispatcherPriority, TimeSpan, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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);
[<System.ComponentModel.Browsable(false)>]
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

相对于调用指定方法的事件队列中的其他 Dispatcher 挂起操作的优先级。

timeout
TimeSpan

等待操作启动的最大时间量。 操作启动后,将在此方法返回之前完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

method
Delegate

对采用多个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

arg
Object

作为参数传递到给定方法中的对象。 如果不需要参数,则可以为 null

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

属性

例外

priority 等于 Inactive

priority 不是有效的优先级。

methodnull

注解

arg如果不需要参数,则可以null

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

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

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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);
[<System.ComponentModel.Browsable(false)>]
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

相对于调用指定方法的事件队列中的其他 Dispatcher 挂起操作的优先级。

method
Delegate

对采用多个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

arg
Object

作为参数传递到给定方法中的对象。

args
Object[]

作为给定方法的自变量传递的对象数组。

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

属性

例外

priority 等于 Inactive

priority 不是有效的优先级。

methodnull

注解

arg如果不需要参数,则可以null

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(Action, DispatcherPriority, CancellationToken, TimeSpan)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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
Public Sub Invoke (callback As Action, priority As DispatcherPriority, cancellationToken As CancellationToken, timeout As TimeSpan)

参数

callback
Action

要通过调度程序调用的操作委托。

priority
DispatcherPriority

确定指定回调相对于中其他挂起操作调用顺序的 Dispatcher优先级。

cancellationToken
CancellationToken

指示是否取消操作的对象。

timeout
TimeSpan

等待操作启动的最大时间量。 操作启动后,将在此方法返回之前完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

例外

callbacknull

timeout 是除 -1 以外的负数,此方法在线程之间调用。

priority 不是有效的优先级。

适用于

Invoke(DispatcherPriority, TimeSpan, Delegate)

按指定的优先级并使用指定的超时值在创建 Dispatcher 的线程上同步执行指定的委托。

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);
[<System.ComponentModel.Browsable(false)>]
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

相对于调用指定方法的事件队列中的其他 Dispatcher 挂起操作的优先级。

timeout
TimeSpan

等待操作启动的最大时间量。 操作启动后,将在此方法返回之前完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

method
Delegate

对不采用任何参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

属性

例外

methodnull

timeout 是除 -1 以外的负数,此方法在线程之间调用。

priority 等于 Inactive

priority 不是有效的优先级。

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(DispatcherPriority, Delegate, Object)

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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);
[<System.ComponentModel.Browsable(false)>]
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

相对于调用指定方法的事件队列中的其他 Dispatcher 挂起操作的优先级。

method
Delegate

对采用一个参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

arg
Object

作为参数传递到给定方法中的对象。

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

属性

例外

priority 等于 Inactive

priority 不是有效的优先级。

methodnull

注解

arg如果不需要参数,则可以null

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

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

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。

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

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

timeout
TimeSpan

等待操作启动的最大时间量。 操作启动后,将在此方法返回之前完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

priority
DispatcherPriority

相对于调用指定方法的事件队列中的其他 Dispatcher 挂起操作的优先级。

args
Object[]

作为给定方法的自变量传递的对象数组。 可以为 null

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

例外

methodnull

timeout 是除 -1 以外的负数,此方法在线程之间调用。

priority 等于 Inactive

priority 不是有效的优先级。

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(Delegate, TimeSpan, Object[])

用与 Dispatcher 关联的线程上的指定参数,按指定优先级同步执行指定时间范围内的指定委托。

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

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

timeout
TimeSpan

等待操作启动的最大时间量。 但是,操作启动后,此方法返回之前会完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

args
Object[]

作为给定方法的自变量传递的对象数组。 如果不需要任何参数,则可以 null

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

例外

methodnull

timeout 是除 -1 以外的负数,并且要跨线程调用。

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(Action, DispatcherPriority, CancellationToken)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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
Public Sub Invoke (callback As Action, priority As DispatcherPriority, cancellationToken As CancellationToken)

参数

callback
Action

要通过调度程序调用的委托。

priority
DispatcherPriority

确定指定回调相对于中其他挂起操作调用顺序的 Dispatcher优先级。

cancellationToken
CancellationToken

指示是否取消操作的对象。

适用于

Invoke(DispatcherPriority, Delegate)

在与之关联的线程 Dispatcher 上以指定的优先级同步执行指定的委托。

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);
[<System.ComponentModel.Browsable(false)>]
member this.Invoke : System.Windows.Threading.DispatcherPriority * Delegate -> obj
Public Function Invoke (priority As DispatcherPriority, method As Delegate) As Object

参数

priority
DispatcherPriority

调用指定方法的优先级,相对于事件队列中的其他 Dispatcher 挂起操作。

method
Delegate

对不采用任何参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

属性

例外

priority 等于 Inactive

priority 不是有效的优先级。

methodnull

示例

以下示例将委托置于Dispatcher使用Invoke位置Normal

// 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

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(Delegate, Object[])

用与 Dispatcher 关联的线程上的指定参数同步执行指定委托。

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

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

args
Object[]

作为给定方法的自变量传递的对象数组。 可以为 null

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke(Action, DispatcherPriority)

在与 Action 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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

要通过调度程序调用的委托。

priority
DispatcherPriority

确定指定回调相对于中其他挂起操作调用顺序的 Dispatcher优先级。

适用于

Invoke(Action)

在与 Action 关联的线程上同步执行指定的 Dispatcher

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

参数

callback
Action

要通过调度程序调用的委托。

注解

默认优先级为 DispatcherPriority.Send.

适用于

Invoke(Delegate, DispatcherPriority, Object[])

按指定的优先级并使用指定的参数在与 Dispatcher 关联的线程上同步执行指定的委托。

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

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。

priority
DispatcherPriority

调用指定方法的优先级,相对于事件队列中的其他 Dispatcher 挂起操作。

args
Object[]

作为给定方法的自变量传递的对象数组。 可以为 null

返回

Object

正在被调用的委托的返回值,如果该委托没有返回值,则为 null

注解

在 WPF 中,只有创建线程 DispatcherObject 才能访问该对象。 例如,从主 UI 线程中分离的后台线程无法更新在 UI 线程上创建的内容 Button 。 为了使后台线程能够访问其 ButtonContent 属性,后台线程必须将工作委托给 Dispatcher 与 UI 线程关联的工作。 这可以通过使用或InvokeBeginInvoke实现。 Invoke 是同步的, BeginInvoke 是异步的。 该操作将添加到指定DispatcherPriority位置的事件队列Dispatcher中。

Invoke 是同步操作;因此,在回调返回之前,控件不会返回到调用对象。

适用于

Invoke<TResult>(Func<TResult>)

在与 Func<TResult> 关联的线程上同步执行指定的 Dispatcher

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

指定委托的返回值类型。

参数

callback
Func<TResult>

要通过调度程序调用的委托。

返回

TResult

返回 callback的值。

适用于

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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

指定委托的返回值类型。

参数

callback
Func<TResult>

要通过调度程序调用的委托。

priority
DispatcherPriority

确定指定回调相对于中其他挂起操作调用顺序的 Dispatcher优先级。

返回

TResult

返回 callback的值。

适用于

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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
Public Function Invoke(Of TResult) (callback As Func(Of TResult), priority As DispatcherPriority, cancellationToken As CancellationToken) As TResult

类型参数

TResult

指定委托的返回值类型。

参数

callback
Func<TResult>

要通过调度程序调用的委托。

priority
DispatcherPriority

确定指定回调相对于中其他挂起操作调用顺序的 Dispatcher优先级。

cancellationToken
CancellationToken

指示是否取消操作的对象。

返回

TResult

返回 callback的值。

适用于

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

在与 Func<TResult> 关联的线程上,以指定的优先级,同步执行指定的 Dispatcher

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
Public Function Invoke(Of TResult) (callback As Func(Of TResult), priority As DispatcherPriority, cancellationToken As CancellationToken, timeout As TimeSpan) As TResult

类型参数

TResult

指定委托的返回值类型。

参数

callback
Func<TResult>

要通过调度程序调用的委托。

priority
DispatcherPriority

确定指定回调相对于中其他挂起操作调用顺序的 Dispatcher优先级。

cancellationToken
CancellationToken

指示是否取消操作的对象。

timeout
TimeSpan

等待操作启动的最大时间量。 操作启动后,将在此方法返回之前完成。 若要指定无限等待,请使用值 -1。 在同一线程调用中,任何其他负值都转换为 -1,从而导致无限等待。 在跨线程调用中,任何其他负值都引发一个 ArgumentOutOfRangeException

返回

TResult

返回 callback的值。

例外

callbacknull

timeout 是除 -1 以外的负数,该方法在线程之间调用。

priority 不是有效的优先级。

适用于