ISynchronizeInvoke 介面


提供同步或非同步執行委派 (Delegate) 的方式。Provides a way to synchronously or asynchronously execute a delegate.

public interface class ISynchronizeInvoke
public interface ISynchronizeInvoke
type ISynchronizeInvoke = interface
Public Interface ISynchronizeInvoke


ISynchronizeInvoke介面提供有關發生事件之物件之間的同步和非同步通訊。The ISynchronizeInvoke interface provides synchronous and asynchronous communication between objects about the occurrence of an event. 執行此介面的物件可以接收事件已發生的通知,而且可以回應事件的相關查詢。Objects that implement this interface can receive notification that an event has occurred, and they can respond to queries about the event. 如此一來,用戶端就可以確保一個要求已處理,然後再提交相依于完成第一個的後續要求。In this way, clients can ensure that one request has been processed before they submit a subsequent request that depends on completion of the first.

ISynchronizeInvoke類別提供兩種方式來叫用處理程式:The ISynchronizeInvoke class provides two ways to invoke a process:

  1. 以非同步方式使用 BeginInvoke 方法。Asynchronously, by using the BeginInvoke method. BeginInvoke 啟動進程,然後立即傳回。BeginInvoke starts a process and then returns immediately. 請使用 EndInvoke 來等候進程啟動 BeginInvoke 完成。Use EndInvoke to wait until the process started by BeginInvoke completes.

  2. 以同步方式使用 Invoke 方法。Synchronously, by using the Invoke method. Invoke 啟動進程,等待它完成,然後傳回。Invoke starts a process, waits until it completes, and then returns. Invoke當控制項的主執行緒與呼叫執行緒不同,以將呼叫封送處理至適當的執行緒時,請使用。Use Invoke when the control's main thread is different from the calling thread to marshal the call to the proper thread.


套用 HostProtectionAttribute 至此類別的屬性具有下列 Resources 屬性值: Synchronization | ExternalThreadingThe HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization | ExternalThreading. HostProtectionAttribute 不會影響桌面應用程式 (這些應用程式的啟動方式一般都是按兩下圖示、輸入命令或在瀏覽器輸入 URL)。The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). 如需詳細資訊,請參閱 HostProtectionAttribute 類別或 SQL Server 程式設計和主機保護屬性For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.



取得值,表示當呼叫實作這個介面的物件時,呼叫端是否必須呼叫 Invoke(Delegate, Object[])Gets a value indicating whether the caller must call Invoke(Delegate, Object[]) when calling an object that implements this interface.


BeginInvoke(Delegate, Object[])

在建立此物件的執行緒上以非同步方式執行委派。Asynchronously executes the delegate on the thread that created this object.


等候直到由呼叫 BeginInvoke(Delegate, Object[]) 所啟動的處理序完成,然後傳回處理序所產生的值。Waits until the process started by calling BeginInvoke(Delegate, Object[]) completes, and then returns the value generated by the process.

Invoke(Delegate, Object[])

在建立此物件的執行緒上同步執行委派,並封送處理對建立執行緒的呼叫。Synchronously executes the delegate on the thread that created this object and marshals the call to the creating thread.