CommunicationObject.Close 方法

定義

導致通訊物件從目前的狀態轉換已關閉狀態。Causes a communication object to transition from its current state into the closed state.

多載

Close()

導致通訊物件從目前的狀態轉換已關閉狀態。Causes a communication object to transition from its current state into the closed state.

Close(TimeSpan)

在指定時間間隔內,讓通訊物件從目前的狀態轉換為已關閉狀態。Causes a communication object to transition from its current state into the closed state within a specified interval of time.

Close()

導致通訊物件從目前的狀態轉換已關閉狀態。Causes a communication object to transition from its current state into the closed state.

public:
 virtual void Close();
public void Close ();
abstract member Close : unit -> unit
override this.Close : unit -> unit
Public Sub Close ()

實作

例外狀況

通訊物件並非處於 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 a CommunicationObject to gracefully transition from any state, other than the Closed state, into the Closed state. Close 方法可讓任何未完成的工作在傳回前完成The Close method allows any unfinished work to be completed before returning. (例如,完成傳送任何經過緩衝處理的訊息)。For example, finish sending any buffered messages.

在呼叫 CommunicationObject 方法後,Closing 會進入並維持 Close 狀態,直到轉換至 Closed 狀態完成為止。The CommunicationObject enters the Closing state and remains in it after the Close method is called until the transition to the Closed state is completed. 轉換包含對於 OnClosingOnClose(TimeSpan)OnClosed 進行後續呼叫。The transition consists of making successive calls to OnClosing, OnClose(TimeSpan), and OnClosed.

也有非同步的方式可用於關閉方法,亦即藉由呼叫 BeginClose 啟始。There is also an asynchronous version of the close method that is initiated by calling BeginClose.

Close(TimeSpan)

在指定時間間隔內,讓通訊物件從目前的狀態轉換為已關閉狀態。Causes a communication object to transition from its current state into the closed state within a specified interval of time.

public:
 virtual void Close(TimeSpan timeout);
public void Close (TimeSpan timeout);
abstract member Close : TimeSpan -> unit
override this.Close : TimeSpan -> unit
Public Sub Close (timeout As TimeSpan)

參數

timeout
TimeSpan

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

實作

例外狀況

通訊物件並非處於 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 a CommunicationObject to gracefully transition from any state, other than the Closed state, into the Closed state within a specified interval of time. Close 方法可讓任何未完成的工作在傳回前完成The Close method allows any unfinished work to be completed before returning. (例如,完成傳送任何經過緩衝處理的訊息)。For example, finish sending any buffered messages.

在呼叫 CommunicationObject 方法後,Closing 會進入並維持 Close 狀態,直到轉換至 Closed 狀態完成為止。The CommunicationObject enters the Closing state and remains in it after the Close method is called until the transition to the Closed state is completed. 轉換包含對於 OnClosingOnClose(TimeSpan)OnClosed 進行後續呼叫。The transition consists of making successive calls to OnClosing, OnClose(TimeSpan) and OnClosed.

也有非同步的方式可用於關閉方法,亦即藉由呼叫 BeginClose 啟始。There is also an asynchronous version of the close method that is initiated by calling BeginClose.

適用於