Dispatcher.Invoke 方法

定義

Dispatcher 關聯的執行緒上以同步方式執行指定的委派。Executes the specified delegate synchronously on the thread the Dispatcher is associated with.

多載

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)

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[])

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)

在與 Action 相關聯的執行緒上使用指定優先權同步執行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

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)

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[])

在與 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[])

在與 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)

在與 Action 相關聯的執行緒上使用指定優先權同步執行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

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[])

在與 Dispatcher 相關聯的執行緒上,使用指定的引數同步地執行指定的委派。Executes the specified delegate with the specified arguments synchronously on the thread the Dispatcher is associated with.

Invoke(Action, DispatcherPriority)

在與 Action 相關聯的執行緒上使用指定優先權同步執行指定的 DispatcherExecutes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.

Invoke(Action)

在與 Action 相關聯的執行緒上,同步執行指定的 DispatcherExecutes the specified Action synchronously on the thread the Dispatcher is associated with.

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

在與 Func<TResult> 相關聯的執行緒上,同步執行指定的 DispatcherExecutes the specified Func<TResult> synchronously on the thread the Dispatcher is associated with.

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)

在與 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)

在與 Func<TResult> 相關聯的執行緒上使用指定優先權同步執行指定的 DispatcherExecutes the specified Func<TResult> synchronously at the specified priority on the thread the Dispatcher is associated with.

範例

下列範例會使用Dispatcher Invoke將委派放在上NormalThe 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 執行緒旋轉的背景執行緒無法更新在 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.

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[])

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

相對於 Dispatcher 事件佇列中其他暫止的作業,會先叫用指定的方法。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

timeout
TimeSpan

等待直到作業完成的最長時間。The maximum time to wait for the operation to finish.

method
Delegate

採用多個引數的方法委派,此委派會推入至 Dispatcher 事件佇列。A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

arg
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.

屬性

例外狀況

priority 等於 Inactivepriority is equal to Inactive.

priority 不是有效的 DispatcherPrioritypriority is not a valid DispatcherPriority.

methodnullmethod is null.

備註

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 執行緒旋轉的背景執行緒無法更新在 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.

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)

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

相對於 Dispatcher 事件佇列中其他暫止的作業,會先叫用指定的方法。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

timeout
TimeSpan

等待直到作業完成的最長時間。The maximum time to wait for the operation to finish.

method
Delegate

採用多個引數的方法委派,此委派會推入至 Dispatcher 事件佇列。A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

arg
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 等於 Inactivepriority is equal to Inactive.

priority 不是有效的優先權。priority is not a valid priority.

methodnullmethod is null.

備註

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 執行緒旋轉的背景執行緒無法更新在 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.

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[])

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

相對於 Dispatcher 事件佇列中其他暫止的作業,會先叫用指定的方法。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

method
Delegate

採用多個引數的方法委派,此委派會推入至 Dispatcher 事件佇列。A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

arg
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 等於 Inactivepriority is equal to Inactive.

priority 不是有效的優先權。priority is not a valid priority.

methodnullmethod is null.

備註

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 執行緒旋轉的背景執行緒無法更新在 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.

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)

在與 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

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

priority
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

表示是否要取消動作的物件。An object that indicates whether to cancel the action.

timeout
TimeSpan

等待作業開始的最短時間。The minimum amount of time to wait for the operation to start.

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

相對於 Dispatcher 事件佇列中其他暫止的作業,會先叫用指定的方法。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

timeout
TimeSpan

等待直到作業完成的最長時間。The maximum time to wait for the operation to finish.

method
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 執行緒旋轉的背景執行緒無法更新在 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.

Invoke是同步作業;因此,直到回呼傳回之後,控制項才會回到呼叫物件。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

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

相對於 Dispatcher 事件佇列中其他暫止的作業,會先叫用指定的方法。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

method
Delegate

採用一個引數的方法委派,此委派會推入至 Dispatcher 事件佇列。A delegate to a method that takes one argument, which is pushed onto the Dispatcher event queue.

arg
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 等於 Inactivepriority is equal to Inactive.

priority 不是有效的優先權。priority is not a valid priority.

methodnullmethod is null.

備註

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 執行緒旋轉的背景執行緒無法更新在 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.

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[])

在與 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

接受 args 中指定之參數之方法的委派,它會被推入至 Dispatcher 事件佇列。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

timeout
TimeSpan

等待作業完成的最長時間。The maximum amount of time to wait for the operation to complete.

priority
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 執行緒旋轉的背景執行緒無法更新在 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.

Invoke是同步作業;因此,直到回呼傳回之後,控制項才會回到呼叫物件。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

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

接受 args 中指定之參數之方法的委派,它會被推入至 Dispatcher 事件佇列。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

timeout
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 執行緒旋轉的背景執行緒無法更新在 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.

Invoke是同步作業;因此,直到回呼傳回之後,控制項才會回到呼叫物件。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

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

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

priority
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

表示是否要取消動作的物件。An object that indicates whether to cancel the action.

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

相對於 Dispatcher 事件佇列中其他暫止的作業,會先叫用指定的方法。The priority, relative to the other pending operations in the Dispatcher event queue, the specified method is invoked.

method
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 等於 Inactivepriority is equal to Inactive.

priority 不是有效的優先權。priority is not a valid priority.

methodnullmethod is null.

範例

下列範例會使用Dispatcher Invoke將委派放在上NormalThe 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 執行緒旋轉的背景執行緒無法更新在 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.

Invoke是同步作業;因此,直到回呼傳回之後,控制項才會回到呼叫物件。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

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

接受 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 執行緒旋轉的背景執行緒無法更新在 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.

Invoke是同步作業;因此,直到回呼傳回之後,控制項才會回到呼叫物件。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

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

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

priority
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)

在與 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

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

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

接受 args 中指定之參數之方法的委派,它會被推入至 Dispatcher 事件佇列。A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.

priority
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 執行緒旋轉的背景執行緒無法更新在 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.

Invoke是同步作業;因此,直到回呼傳回之後,控制項才會回到呼叫物件。Invoke is a synchronous operation; therefore, control will not return to the calling object until after the callback returns.

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>

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

傳回

TResult

備註

所傳回callback的值。The value returned by callback.

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>

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

priority
DispatcherPriority

優先權,會決定以何種順序叫用指定的回呼,相對於 Dispatcher 中其他擱置中的作業。The priority that determines in what order the specified callback is invoked relative to the other pending operations in the Dispatcher.

傳回

TResult

備註

所傳回callback的值。The value returned by callback.

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>

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

priority
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

表示是否要取消作業的物件。An object that indicates whether to cancel the operation.

傳回

TResult

備註

所傳回callback的值。The value returned by callback.

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>

要透過發送器叫用的委派。A delegate to invoke through the dispatcher.

priority
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

表示是否要取消作業的物件。An object that indicates whether to cancel the operation.

timeout
TimeSpan

等待作業開始的最短時間。The minimum amount of time to wait for the operation to start.

傳回

TResult

備註

所傳回callback的值。The value returned by callback.

適用於