CommunicationObject.BeginClose 方法

定義

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

多載

BeginClose(AsyncCallback, Object)

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

BeginClose(TimeSpan, AsyncCallback, Object)

開始非同步作業,關閉有已指定逾時的通訊物件。Begins an asynchronous operation to close a communication object with a specified timeout.

BeginClose(AsyncCallback, Object)

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

public:
 virtual IAsyncResult ^ BeginClose(AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginClose (AsyncCallback callback, object state);
abstract member BeginClose : AsyncCallback * obj -> IAsyncResult
override this.BeginClose : AsyncCallback * obj -> IAsyncResult
Public Function BeginClose (callback As AsyncCallback, state As Object) As IAsyncResult

參數

callback
AsyncCallback

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

state
Object

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

傳回

參考非同步關閉作業的 IAsyncResultThe IAsyncResult that references the asynchronous close operation.

實作

例外狀況

通訊物件並非處於 OpenedOpening 狀態,無法修改。The communication object is not in a Opened or Opening state and cannot be modified.

通訊物件處於 ClosingClosed 狀態,無法修改。The communication object is in a Closing or Closed state and cannot be modified.

通訊物件處於 Faulted 狀態,無法修改。The communication object is in a Faulted state and cannot be modified.

已超過為作業分配的預設時間間隔,該作業未完成。The default interval of time that was allotted for the operation was exceeded before the operation was completed.

備註

這個方法可以在預設時間間隔內,將 CommunicationObjectClosed 狀態以外的任何狀態順利轉換至 Closed 狀態。This method causes the CommunicationObject to gracefully transition from any state, other than the Closed state, into the Closed state within a default interval of time. BeginClose 方法可讓任何未完成的工作在傳回前完成The BeginClose method allows any unfinished work to be completed before returning. (例如,完成傳送任何經過緩衝處理的訊息)。For example, finish sending any buffered messages). 如果通訊物件一開始處於 OnBeginOpen(TimeSpan, AsyncCallback, Object) 狀態,這個方法就會呼叫 OpenedThis method calls OnBeginOpen(TimeSpan, AsyncCallback, Object) if the communication object was initially in the Opened state.

BeginClose(TimeSpan, AsyncCallback, Object)

開始非同步作業,關閉有已指定逾時的通訊物件。Begins an asynchronous operation to close a communication object with a specified timeout.

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

參數

timeout
TimeSpan

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

callback
AsyncCallback

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

state
Object

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

傳回

參考非同步關閉作業的 IAsyncResultThe IAsyncResult that references the asynchronous close operation.

實作

例外狀況

通訊物件並非處於 OpenedOpening 狀態,無法修改。The communication object is not in a Opened or Opening state and cannot be modified.

通訊物件處於 ClosingClosed 狀態,無法修改。The communication object is in a Closing or Closed state and cannot be modified.

通訊物件處於 Faulted 狀態,無法修改。The communication object is in a Faulted state and cannot be modified.

已超過為作業分配的預設時間間隔,該作業未完成。The default interval of time that was allotted for the operation was exceeded before the operation was completed.

備註

這個方法可以在指定的時間間隔內,將 CommunicationObjectClosed 狀態以外的任何狀態順利轉換至 Closed 狀態。This method causes the CommunicationObject to gracefully transition from any state, other than the Closed state, into the Closed state with in a specified interval of time. BeginClose 方法可讓任何未完成的工作在傳回前完成The BeginClose method allows any unfinished work to be completed before returning. (例如,完成傳送任何經過緩衝處理的訊息)。For example, finish sending any buffered messages). 如果通訊物件一開始處於 OnBeginClose(TimeSpan, AsyncCallback, Object) 狀態,這個方法就會呼叫 OpenedThis method calls OnBeginClose(TimeSpan, AsyncCallback, Object) if the communication object was initially in the Opened state.

適用於