ICommunicationObject.BeginOpen 方法

定義

開始非同步作業以關閉通訊物件。Begins an asynchronous operation to close a communication object.

多載

BeginOpen(AsyncCallback, Object)

開始非同步作業以開啟通訊物件。Begins an asynchronous operation to open a communication object.

BeginOpen(TimeSpan, AsyncCallback, Object)

開始非同步作業,開啟有已指定時間間隔的通訊物件。Begins an asynchronous operation to open a communication object within a specified interval of time.

備註

BeginOpen 方法會使 ICommunicationObject 進入 Opening 狀態,直到其轉換至 Opened 狀態完成或失敗為止。The BeginOpen method causes an ICommunicationObject to enter into the Opening state where it remains until its transition to the Opened state is completed or fails.

有明確逾時或無明確逾時的版本都會提供。Versions with and without an explicit timeout are provided.

BeginOpen(AsyncCallback, Object)

開始非同步作業以開啟通訊物件。Begins an asynchronous operation to open a communication object.

public:
 IAsyncResult ^ BeginOpen(AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginOpen (AsyncCallback callback, object state);
abstract member BeginOpen : AsyncCallback * obj -> IAsyncResult
Public Function BeginOpen (callback As AsyncCallback, state As Object) As IAsyncResult

參數

callback
AsyncCallback

AsyncCallback 委派,這個委派會接收非同步開啟作業完成的通知。The AsyncCallback delegate that receives notification of the completion of the asynchronous open operation.

state
Object

應用程式所指定的物件,其中包含與非同步開啟作業相關聯的狀態資訊。An object, specified by the application, that contains state information associated with the asynchronous open operation.

傳回

參考非同步開啟作業的 IAsyncResultThe IAsyncResult that references the asynchronous open operation.

例外狀況

ICommunicationObject 無法開啟,而且已進入 Faulted 狀態。The ICommunicationObject was unable to be opened and has entered the Faulted state.

經過預設的開啟逾時時間之後,ICommunicationObject 就可以進入 Opened 狀態,而且也已進入 Faulted 狀態。The default open timeout elapsed before the ICommunicationObject was able to enter the Opened state and has entered the Faulted state.

備註

ICommunicationObject 具現化時,它會以 Created 狀態開始。When an ICommunicationObject is instantiated, it begins in the Created state. Created 狀態下,可以設定物件 (例如可以設定屬性或註冊事件),但是仍無法傳送或接收訊息。In the Created state, the object can be configured (for example, properties can be set, or events can be registered), but it is not yet usable to send or receive messages. BeginOpen 方法會使 ICommunicationObject 進入 Opening 狀態,直到開啟的作業成功、開啟的作業超時或失敗,以及物件發生錯誤,或 ICommunicationObject 已中止。The BeginOpen method causes an ICommunicationObject to enter into the Opening state where it remains until the open operation succeeds, the open operation times out or fails and the object becomes faulted, or the ICommunicationObject is aborted.

Opened 狀態中,ICommunicationObject 可供使用(例如,可以接收訊息),但無法再進行設定。In the Opened state, the ICommunicationObject is usable (for example, messages can be received), but it is no longer configurable.

BeginOpen(TimeSpan, AsyncCallback, Object)

開始非同步作業,開啟有已指定時間間隔的通訊物件。Begins an asynchronous operation to open a communication object within a specified interval of time.

public:
 IAsyncResult ^ BeginOpen(TimeSpan timeout, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state);
abstract member BeginOpen : TimeSpan * AsyncCallback * obj -> IAsyncResult
Public Function BeginOpen (timeout As TimeSpan, callback As AsyncCallback, state As Object) As IAsyncResult

參數

timeout
TimeSpan

TimeSpan,指定必須在逾時前多久完成傳送作業。The TimeSpan that specifies how long the send operation has to complete before timing out.

callback
AsyncCallback

AsyncCallback 委派,這個委派會接收非同步開啟作業完成的通知。The AsyncCallback delegate that receives notification of the completion of the asynchronous open operation.

state
Object

應用程式所指定的物件,其中包含與非同步開啟作業相關聯的狀態資訊。An object, specified by the application, that contains state information associated with the asynchronous open operation.

傳回

參考非同步開啟作業的 IAsyncResultThe IAsyncResult that references the asynchronous open operation.

例外狀況

ICommunicationObject 無法開啟,而且已進入 Faulted 狀態。The ICommunicationObject was unable to be opened and has entered the Faulted state.

經過指定的逾時時間之後,ICommunicationObject 就可以進入 Opened 狀態,而且也已進入 Faulted 狀態。The specified timeout elapsed before the ICommunicationObject was able to enter the Opened state and has entered the Faulted state.

備註

ICommunicationObject 具現化時,它會以 Created 狀態開始。When an ICommunicationObject is instantiated, it begins in the Created state. Created 狀態下,可以設定物件 (例如可以設定屬性或註冊事件),但是仍無法傳送或接收訊息。In the Created state, the object can be configured (for example, properties can be set, or events can be registered), but it is not yet usable to send or receive messages. Open 方法會使 ICommunicationObject 進入 Opening 狀態,直到開啟的作業成功、開啟的作業超時或失敗,以及物件發生錯誤,或 ICommunicationObject 已中止。The Open method causes an ICommunicationObject to enter into the Opening state where it remains until the open operation succeeds, the open operation times out or fails and the object becomes faulted, or the ICommunicationObject is aborted.

Opened 狀態中,ICommunicationObject 可供使用(例如,可以接收訊息),但無法再進行設定。In the Opened state, the ICommunicationObject is usable (for example, messages can be received), but it is no longer configurable.

給實施者的注意事項

如果超過指定的 timeout,則作業必須擲回 TimeoutExceptionThe operation must throw a TimeoutException if the specified timeout is exceeded.

適用於