Dispatcher.BeginInvoke Dispatcher.BeginInvoke Dispatcher.BeginInvoke Dispatcher.BeginInvoke Method

定义

在与 Dispatcher 关联的线程上异步执行委托。Executes a delegate asynchronously on the thread the Dispatcher is associated with.

重载

BeginInvoke(Delegate, Object[]) BeginInvoke(Delegate, Object[]) BeginInvoke(Delegate, Object[]) BeginInvoke(Delegate, Object[])

用在其上创建了 Dispatcher 的线程的指定参数异步执行指定委托。Executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher was created on.

BeginInvoke(DispatcherPriority, Delegate) BeginInvoke(DispatcherPriority, Delegate) BeginInvoke(DispatcherPriority, Delegate) BeginInvoke(DispatcherPriority, Delegate)

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

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

用在其上创建了 Dispatcher 的线程上的指定参数,按指定优先级异步执行指定委托。Executes the specified delegate asynchronously with the specified arguments, at the specified priority, on the thread that the Dispatcher was created on.

BeginInvoke(DispatcherPriority, Delegate, Object) BeginInvoke(DispatcherPriority, Delegate, Object) BeginInvoke(DispatcherPriority, Delegate, Object) BeginInvoke(DispatcherPriority, Delegate, Object)

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

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

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

注解

WPFWPF中,只有创建的DispatcherObject线程才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 ui 线程旋转的后台线程无法更新在 ui 线程上创建的的内容ButtonFor 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内容属性,后台线程必须将工作委托给与 UI 线程关联的。 DispatcherIn 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. 这可以Invoke通过使用或BeginInvoke来完成。This is accomplished by using either Invoke or BeginInvoke. Invoke是同步的BeginInvoke ,并且是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 操作将添加到指定Dispatcher DispatcherPriority的的事件队列中。The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

BeginInvoke是异步的;因此,控件在调用后立即返回到调用对象。BeginInvoke is asynchronous; therefore, control returns immediately to the calling object after it is called.

BeginInvoke返回一个DispatcherOperation对象,该对象可用于在委托位于事件队列中时与委托交互。BeginInvoke returns a DispatcherOperation object that can be used to interact with the delegate when the delegate is in the event queue.

BeginInvoke返回的DispatcherOperation对象可通过多种方式用于与指定的委托交互,例如:The DispatcherOperation object returned by BeginInvoke can be used in several ways to interact with the specified delegate, such as:

  • DispatcherPriority更改委托的,因为它在事件队列中挂起执行。Changing the DispatcherPriority of the delegate as it is pending execution in the event queue.

  • 从事件队列中删除委托。Removing the delegate from the event queue.

  • 正在等待委托返回。Waiting for the delegate to return.

  • 获取委托在执行后返回的值。Obtaining the value that the delegate returns after it is executed.

如果在BeginInvoke同一DispatcherPriority位置进行多个调用,则它们将按调用的顺序执行。If multiple BeginInvoke calls are made at the same DispatcherPriority, they will be executed in the order the calls were made.

如果BeginInvoke DispatcherOperation对已关闭的调用,则返回的状态属性设置为AbortedDispatcherIf BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

BeginInvoke(Delegate, Object[]) BeginInvoke(Delegate, Object[]) BeginInvoke(Delegate, Object[]) BeginInvoke(Delegate, Object[])

用在其上创建了 Dispatcher 的线程的指定参数异步执行指定委托。Executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher was created on.

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

参数

method
Delegate Delegate Delegate Delegate

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。The 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.

返回

调用 BeginInvoke 之后立即返回的对象,可用来与事件队列中挂起执行的委托进行交互。An object, which is returned immediately after BeginInvoke is called, that can be used to interact with the delegate as it is pending execution in the event queue.

注解

BeginInvoke返回的DispatcherOperation对象可通过多种方式用于与指定的委托交互,例如:The DispatcherOperation object returned by BeginInvoke can be used in several ways to interact with the specified delegate, such as:

  • DispatcherPriority更改委托的,因为它在事件队列中挂起执行。Changing the DispatcherPriority of the delegate as it is pending execution in the event queue.

  • 从事件队列中删除委托。Removing the delegate from the event queue.

  • 正在等待委托返回。Waiting for the delegate to return.

  • 获取委托在执行后返回的值。Obtaining the value that the delegate returns after it is executed.

BeginInvoke是异步的;因此,控件在调用后立即返回到调用对象。BeginInvoke is asynchronous; therefore, control returns immediately to the calling object after it is called.

WPFWPF中,只有创建的DispatcherObject线程才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 ui 线程旋转的后台线程无法更新在 ui 线程上创建的的内容ButtonFor 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内容属性,后台线程必须将工作委托给与 UI 线程关联的。 DispatcherIn 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. 这可以Invoke通过使用或BeginInvoke来完成。This is accomplished by using either Invoke or BeginInvoke. Invoke是同步的BeginInvoke ,并且是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 操作将添加到指定Dispatcher DispatcherPriority的的事件队列中。The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

如果BeginInvoke DispatcherOperation对已关闭的调用,则返回的状态属性设置为AbortedDispatcherIf BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

BeginInvoke(DispatcherPriority, Delegate) BeginInvoke(DispatcherPriority, Delegate) BeginInvoke(DispatcherPriority, Delegate) BeginInvoke(DispatcherPriority, Delegate)

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

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

参数

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 事件队列中。The delegate to a method that takes no arguments, which is pushed onto the Dispatcher event queue.

返回

调用 BeginInvoke 之后立即返回的对象,可用来与事件队列中挂起执行的委托进行交互。An object, which is returned immediately after BeginInvoke is called, that can be used to interact with the delegate as it is pending execution in the event queue.

异常

示例

下面的示例演示如何在Dispatcher上放置操作。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.

public delegate void NextPrimeDelegate();
Public Delegate Sub NextPrimeDelegate()

接下来BeginInvoke(DispatcherPriority, Delegate) ,调用。Next, BeginInvoke(DispatcherPriority, Delegate) is called. 由于每DispatcherObject个都有一个属性, Dispatcher该属性返回与之关联的Dispatcher ,因此,所需DispatcherObject的通过查询来获得ButtonstartStopButton在此示例中为一个名为的。Because every DispatcherObject has a property that returns the Dispatcher it is associated with, the desired Dispatcher is obtained by querying the DispatcherObject, in this case a Button named startStopButton. 调用BeginInvoke(DispatcherPriority, Delegate)将使用两个参数:设置为DispatcherPriority.Normal的优先级,以及通过委托NextPrimeDelegate的实例传入的回调。The 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.

startStopButton.Dispatcher.BeginInvoke(
    DispatcherPriority.Normal,
    new NextPrimeDelegate(CheckNextNumber));
startStopButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New NextPrimeDelegate(AddressOf CheckNextNumber))

注解

如果在BeginInvoke同一DispatcherPriority位置进行多个调用,则它们将按调用的顺序执行。If multiple BeginInvoke calls are made at the same DispatcherPriority, they will be executed in the order the calls were made.

BeginInvoke返回一个DispatcherOperation对象,该对象可用于在委托位于事件队列中时与委托交互。BeginInvoke returns a DispatcherOperation object that can be used to interact with the delegate when the delegate is in the event queue.

BeginInvoke返回的DispatcherOperation对象可通过多种方式用于与指定的委托交互,例如:The DispatcherOperation object returned by BeginInvoke can be used in several ways to interact with the specified delegate, such as:

  • DispatcherPriority更改委托的,因为它在事件队列中挂起执行。Changing the DispatcherPriority of the delegate as it is pending execution in the event queue.

  • 从事件队列中删除委托。Removing the delegate from the event queue.

  • 正在等待委托返回。Waiting for the delegate to return.

  • 获取委托在执行后返回的值。Obtaining the value that the delegate returns after it is executed.

BeginInvoke是异步的;因此,控件在调用后立即返回到调用对象。BeginInvoke is asynchronous; therefore, control returns immediately to the calling object after it is called.

WPFWPF中,只有创建的DispatcherObject线程才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 ui 线程旋转的后台线程无法更新在 ui 线程上创建的的内容ButtonFor 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内容属性,后台线程必须将工作委托给与 UI 线程关联的。 DispatcherIn 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. 这可以Invoke通过使用或BeginInvoke来完成。This is accomplished by using either Invoke or BeginInvoke. Invoke是同步的BeginInvoke ,并且是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 操作将添加到指定Dispatcher DispatcherPriority的的事件队列中。The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

如果BeginInvoke DispatcherOperation对已关闭的调用,则返回的状态属性设置为AbortedDispatcherIf BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

另请参阅

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

用在其上创建了 Dispatcher 的线程上的指定参数,按指定优先级异步执行指定委托。Executes the specified delegate asynchronously with the specified arguments, at the specified priority, on the thread that the Dispatcher was created on.

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

参数

method
Delegate Delegate Delegate Delegate

对采用 args 中指定参数的方法的委托,该委托将被推送到 Dispatcher 事件队列中。The 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.

返回

调用 BeginInvoke 之后立即返回的对象,可用来与事件队列中挂起执行的委托进行交互。An object, which is returned immediately after BeginInvoke is called, that can be used to interact with the delegate as it is pending execution in the event queue.

注解

BeginInvoke返回的DispatcherOperation对象可通过多种方式用于与指定的委托交互,例如:The DispatcherOperation object returned by BeginInvoke can be used in several ways to interact with the specified delegate, such as:

  • DispatcherPriority更改委托的,因为它在事件队列中挂起执行。Changing the DispatcherPriority of the delegate as it is pending execution in the event queue.

  • 从事件队列中删除委托。Removing the delegate from the event queue.

  • 正在等待委托返回。Waiting for the delegate to return.

  • 获取委托在执行后返回的值。Obtaining the value that the delegate returns after it is executed.

BeginInvoke是异步的;因此,控件在调用后立即返回到调用对象。BeginInvoke is asynchronous; therefore, control returns immediately to the calling object after it is called.

WPFWPF中,只有创建的DispatcherObject线程才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 ui 线程旋转的后台线程无法更新在 ui 线程上创建的的内容ButtonFor 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内容属性,后台线程必须将工作委托给与 UI 线程关联的。 DispatcherIn 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. 这可以Invoke通过使用或BeginInvoke来完成。This is accomplished by using either Invoke or BeginInvoke. Invoke是同步的BeginInvoke ,并且是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 操作将添加到指定Dispatcher DispatcherPriority的的事件队列中。The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

如果BeginInvoke DispatcherOperation对已关闭的调用,则返回的状态属性设置为AbortedDispatcherIf BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

BeginInvoke(DispatcherPriority, Delegate, Object) BeginInvoke(DispatcherPriority, Delegate, Object) BeginInvoke(DispatcherPriority, Delegate, Object) BeginInvoke(DispatcherPriority, Delegate, Object)

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

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

参数

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

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

返回

调用 BeginInvoke 之后立即返回的对象,可用来与事件队列中挂起执行的委托进行交互。An object, which is returned immediately after BeginInvoke is called, that can be used to interact with the delegate as it is pending execution in the event queue.

异常

示例

下面的示例演示如何在Dispatcher上放置操作。The following example shows how to place an operation onto a Dispatcher.

首先,创建一个接受一个参数(在本例中为字符串)的委托。First, a delegate is created that accepts one argument, in this case a string.

private delegate void OneArgDelegate(String arg);
Private Delegate Sub OneArgDelegate(ByVal arg As String)

接下来BeginInvoke(DispatcherPriority, Delegate, Object) ,调用。Next, BeginInvoke(DispatcherPriority, Delegate, Object) is called. 由于每DispatcherObject个都有一个属性, Dispatcher该属性返回与之关联的Dispatcher ,因此,所需DispatcherObject的通过查询来获得GridtomorrowsWeather在此示例中为一个名为的。Because every DispatcherObject has a property that returns the Dispatcher it is associated with, the desired Dispatcher is obtained by querying the DispatcherObject, in this case a Grid named tomorrowsWeather. 对的调用BeginInvoke(DispatcherPriority, Delegate, Object)采用三个参数:优先级设置为DispatcherPriority.Normal; 通过委托OneArgDelegate的实例传入的回调; 以及一个名weather为的字符串,它是回调的参数。The call to BeginInvoke(DispatcherPriority, Delegate, Object) takes three parameters: the priority, which is set to DispatcherPriority.Normal; the callback, which is passed in through an instance of the delegate OneArgDelegate; and a string named weather, which is the argument for the callback.

// Schedule the update function in the UI thread.
tomorrowsWeather.Dispatcher.BeginInvoke(
    System.Windows.Threading.DispatcherPriority.Normal,
    new OneArgDelegate(UpdateUserInterface), 
    weather);
' Schedule the update function in the UI thread.
tomorrowsWeather.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, New OneArgDelegate(AddressOf UpdateUserInterface), weather)

注解

Arg如果不null需要参数,则可以为。Arg can be null if no arguments are needed.

BeginInvoke返回一个DispatcherOperation对象,该对象可用于在委托位于事件队列中时与委托交互。BeginInvoke returns a DispatcherOperation object that can be used to interact with the delegate when the delegate is in the event queue.

BeginInvoke返回的DispatcherOperation对象可通过多种方式用于与指定的委托交互,例如:The DispatcherOperation object returned by BeginInvoke can be used in several ways to interact with the specified delegate, such as:

  • DispatcherPriority更改委托的,因为它在事件队列中挂起执行。Changing the DispatcherPriority of the delegate as it is pending execution in the event queue.

  • 从事件队列中删除委托。Removing the delegate from the event queue.

  • 正在等待委托返回。Waiting for the delegate to return.

  • 获取委托在执行后返回的值。Obtaining the value that the delegate returns after it is executed.

BeginInvoke是异步的;因此,控件在调用后立即返回到调用对象。BeginInvoke is asynchronous; therefore, control returns immediately to the calling object after it is called.

WPFWPF中,只有创建的DispatcherObject线程才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 ui 线程旋转的后台线程无法更新在 ui 线程上创建的的内容ButtonFor 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内容属性,后台线程必须将工作委托给与 UI 线程关联的。 DispatcherIn 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. 这可以Invoke通过使用或BeginInvoke来完成。This is accomplished by using either Invoke or BeginInvoke. Invoke是同步的BeginInvoke ,并且是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 操作将添加到指定Dispatcher DispatcherPriority的的事件队列中。The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

如果在BeginInvoke同一DispatcherPriority位置进行多个调用,则它们将按调用的顺序执行。If multiple BeginInvoke calls are made at the same DispatcherPriority, they will be executed in the order the calls were made.

如果BeginInvoke DispatcherOperation对已关闭的调用,则返回的状态属性设置为AbortedDispatcherIf BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

另请参阅

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

按指定的优先级并使用指定的参数数组在与 Dispatcher 关联的线程上异步执行指定的委托。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:
 System::Windows::Threading::DispatcherOperation ^ BeginInvoke(System::Windows::Threading::DispatcherPriority priority, Delegate ^ method, System::Object ^ arg, ... cli::array <System::Object ^> ^ args);
[System.ComponentModel.Browsable(false)]
public System.Windows.Threading.DispatcherOperation BeginInvoke (System.Windows.Threading.DispatcherPriority priority, Delegate method, object arg, params object[] args);
member this.BeginInvoke : System.Windows.Threading.DispatcherPriority * Delegate * obj * obj[] -> System.Windows.Threading.DispatcherOperation
Public Function BeginInvoke (priority As DispatcherPriority, method As Delegate, arg As Object, ParamArray args As Object()) As DispatcherOperation

参数

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

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

args
Object[]

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

返回

调用 BeginInvoke 之后立即返回的对象,可用来与 Dispatcher 队列中挂起执行的委托进行交互。An object, which is returned immediately after BeginInvoke is called, that can be used to interact with the delegate as it is pending execution in the Dispatcher queue.

异常

注解

如果arg不需要任何null参数,则该参数可以为。The arg parameter can be null if no arguments are needed.

BeginInvoke返回一个DispatcherOperation对象,该对象可用于在委托位于事件队列中时与委托交互。BeginInvoke returns a DispatcherOperation object that can be used to interact with the delegate when the delegate is in the event queue.

BeginInvoke返回的DispatcherOperation对象可通过多种方式用于与指定的委托交互,例如:The DispatcherOperation object returned by BeginInvoke can be used in several ways to interact with the specified delegate, such as:

  • DispatcherPriority更改委托的,因为它在事件队列中挂起执行。Changing the DispatcherPriority of the delegate as it is pending execution in the event queue.

  • 从事件队列中删除委托。Removing the delegate from the event queue.

  • 正在等待委托返回。Waiting for the delegate to return.

  • 获取委托在执行后返回的值。Obtaining the value that the delegate returns after it is executed.

BeginInvoke是异步的;因此,控件在调用后立即返回到调用对象。BeginInvoke is asynchronous; therefore, control returns immediately to the calling object after it is called.

WPFWPF中,只有创建的DispatcherObject线程才能访问该对象。In WPFWPF, only the thread that created a DispatcherObject may access that object. 例如,从主 ui 线程旋转的后台线程无法更新在 ui 线程上创建的的内容ButtonFor 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内容属性,后台线程必须将工作委托给与 UI 线程关联的。 DispatcherIn 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. 这可以Invoke通过使用或BeginInvoke来完成。This is accomplished by using either Invoke or BeginInvoke. Invoke是同步的BeginInvoke ,并且是异步的。Invoke is synchronous and BeginInvoke is asynchronous. 操作将添加到指定Dispatcher DispatcherPriority的的事件队列中。The operation is added to the event queue of the Dispatcher at the specified DispatcherPriority.

如果在BeginInvoke同一DispatcherPriority位置进行多个调用,则它们将按调用的顺序执行。If multiple BeginInvoke calls are made at the same DispatcherPriority, they will be executed in the order the calls were made.

如果BeginInvoke DispatcherOperation对已关闭的调用,则返回的状态属性设置为AbortedDispatcherIf BeginInvoke is called on a Dispatcher that has shut down, the status property of the returned DispatcherOperation is set to Aborted.

另请参阅

适用于