CommunicationState 列舉

定義

定義 ICommunicationObject 可處於其中的狀態。Defines the states in which an ICommunicationObject can exist.

public enum class CommunicationState
public enum CommunicationState
type CommunicationState = 
Public Enum CommunicationState
繼承
CommunicationState

欄位

Closed 4

指出該通訊物件已關閉,而且不再提供使用。Indicates that the communication object has been closed and is no longer usable.

Closing 3

指出該通訊物件將轉換成 Closed 狀態。Indicates that the communication object is transitioning to the Closed state.

Created 0

指出物件已產生而且是可設定狀態,但是尚未開啟或還未準備好提供使用。Indicates that the communication object has been instantiated and is configurable, but not yet open or ready for use.

Faulted 5

指出該通訊物件遇到其無法復原並導致其不再提供使用的錯誤。Indicates that the communication object has encountered an error or fault from which it cannot recover and from which it is no longer usable.

Opened 2

指出該通訊物件現在已開啟,而且已準備好提供使用。Indicates that the communication object is now open and ready to be used.

Opening 1

指出該通訊物件將從 Created 狀態轉換為 Opened 狀態。Indicates that the communication object is being transitioned from the Created state to the Opened state.

備註

這個列舉會定義系統中所有通訊物件可有效轉換至其中的狀態,這些物件包括通道、接聽程式、處理站、發送器和服務主機。This enumeration defines the states that are valid for all communication objects in the system, including channels, listeners, factories, dispatchers, and service hosts.

管理這些狀態和與其可能有關聯的事件之間之轉換的方法會定義在 ICommunicationObject 介面中。The methods that manage transitions between these states and the events that can be associated with them are defined in the ICommunicationObject interface. 物件的狀態可使用 State 屬性來取得。The state of an object can be obtained using the State property.

通訊物件可以處於四種主要狀態和兩種過渡狀態。There are four main states and two transient states that a communication object can occupy. 主要狀態為:The main states are:

  • 建立時間Created

  • OpenedOpened

  • 關閉Closed

  • FaultedFaulted

在這些主要狀態之間轉換時,通訊物件可能會處於兩種過渡狀態:The two transitory states that a communication object can occupy when transitioning between these main states are:

  • 正在開啟Opening

  • ClosingClosing

通訊物件可以設定為已建立的狀態。The communication object can be configured in the Created state. 例如,它的屬性可以變更,而它的事件可以註冊。For example, its properties can be changed, and its events can be registered. 在這個狀態下不會發生任何輸入或輸出。No input or output can occur in this state. 這樣一來,可能在這個狀態中的訊息就無法從通道傳送或接收。So messages, for example, cannot be sent or received from a channel in this state.

開啟是在叫用 Open 方法時,通訊物件所輸入的暫時性狀態。The Opening is a temporary state that the communication object enters when the Open method is invoked. 除非在衍生類別中另有附註,否則無法設定處於開啟狀態的物件。Unless otherwise noted on derived classes, objects in the opening state cannot be configured. 此轉換狀態只能從已建立的狀態輸入。This transition state can only be entered from the Created state.

當開啟的進程完成時,物件會轉換為已開啟狀態。Objects transition to the Opened state when the open process completes. 此轉換至已開啟狀態只會從開啟狀態生效。This transition to the Opened state is only valid from the Opening state. 除非在衍生類別中另有附註,否則現在狀態物件的組態是停用的。Unless otherwise noted on derived classes, the configuration of the object is now disabled. 此時,物件完全可供訊息傳輸使用。At this point, the object is fully usable for message transfers.

關閉是暫時的狀態,物件會在叫用 Close 方法以進行正常關機或物件已中止時,進入該狀態。The Closing is a temporary state that the object enters when the Close method is invoked for a graceful shutdown or the object is aborted. 此時,物件就無法使用 (如果尚未準備好)。At this point, the object becomes (if not already) unusable. 此轉換會從 [已關閉] 狀態以外的任何狀態中有效。This transition is valid from any state except the Closed state.

[已關閉] 狀態相當於 [已處置],而且仍然可以檢查物件的設定。The Closed state is equivalent to being disposed and the configuration of the object can still be inspected.

錯誤狀態是用來指出物件已轉換成無法再使用它的狀態。The Faulted state is used to indicate that the object has transitioned to a state where it can no longer be used. 有兩種主要案例會發生這種情況:There are two primary scenarios where this can happen:

  • 如果 Open 方法因任何理由發生失敗,此物件會轉換至錯誤的狀態。If the Open method fails for any reason, the object transitions to the faulted state.

  • 如果工作階段架構通道偵測到無法復原的錯誤,該通道就會轉換至錯誤的狀態。If a session-based channel detects an error that it cannot recover from, it transitions to the faulted state. 執行個體可能會在存在通訊協定錯誤 (也就是說,它在無效階段時收到通訊協定訊息) 或發生遠端端點中止工作階段的情況下,出現這種情形。This can happen for instance if there is a protocol error (that is, it receives a protocol message at an invalid time) or if the remote endpoint aborts the session.

處於錯誤狀態的物件不會關閉,而且可能會保留資源。An object in the Faulted state is not closed and may be holding resources. Abort 方法應該要用於關閉已發生錯誤的物件。The Abort method should be used to close an object that has faulted. 如果在發生錯誤狀態的物件上呼叫 Close,則會擲回 CommunicationObjectFaultedException,因為無法正常關閉物件。If Close is called on an object in the Faulted state, a CommunicationObjectFaultedException is thrown because the object cannot be gracefully closed.

適用於