EventListener EventListener EventListener EventListener Class

定義

提供方法來啟用及停用來自事件來源的事件。Provides methods for enabling and disabling events from event sources.

public ref class EventListener abstract : IDisposable
public abstract class EventListener : IDisposable
type EventListener = class
    interface IDisposable
Public MustInherit Class EventListener
Implements IDisposable
繼承
EventListenerEventListenerEventListenerEventListener
實作

備註

事件接聽程式表示產生的事件來源的所有事件的目標 (EventSource物件) 目前的應用程式定義域中的實作。An event listener represents the target for all events generated by event source (EventSource object) implementations in the current application domain. 建立新的事件接聽程式時,它會以邏輯方式附加至應用程式定義域中的所有事件來源。When a new event listener is created, it is logically attached to all event sources in that application domain.

注意

此類型會實作IDisposable介面。This type implements the IDisposable interface. 當您完成使用型別時,您必須處置它的直接或間接。When you have finished using the type, you must dispose of it either directly or indirectly. 若要直接處置型別,呼叫其Dispose方法中的try / catch區塊。To dispose of the type directly, call its Dispose method in a try/catch block. 若要處置它間接,使用的語言建構這類using(在 C# 中) 或Using(在 Visual Basic)。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 如需詳細資訊,請參閱 「 使用物件,實作 IDisposable 」 一節IDisposable介面 > 主題。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

事件接聽程式可以啟用或停用每個目前事件來源為基礎,使用事件層級 (EventLevel) 和事件的關鍵字 (EventKeywords) 來進一步限制要傳送至接聽程式之事件集。An event listener can enable or disable on a per-current event source basis by using event levels (EventLevel) and event keywords (EventKeywords) to further restrict the set of events to be sent to the listener. 接聽程式也可以傳送任意命令給特定的目前事件來源使用SendCommand方法。The listener can also send arbitrary commands to a specific current event source by using the SendCommand method. 命令的意義是特有的事件來源實作。The meanings of the commands are specific to the implementation of the event source.

如果Guid中的屬性EventSource用來啟用或停用事件的物件是Empty,應用程式定義域中的所有事件來源會受到都影響。If the Guid property in the EventSource object that is used to enable or disable events is Empty, all event sources in the application domain are affected.

在單一應用程式定義域中,可以定義多個事件接聽程式。Multiple event listeners can be defined in a single application domain. 每個接聽程式是邏輯上獨立於其他接聽程式,以便啟用或停用一個接聽程式的事件會影響該接聽項。Each listener is logically independent of the other listeners so that events that are enabled or disabled by one listener affect only that listener. 使用傳送的命令可能會SendCommand方法,以進行語意的作業 (例如記憶體回收或排清資料) 會影響其他的接聽程式,但這是例外狀況,而不是此規則。It is possible for commands sent with the SendCommand method to do a semantic operation (such as a garbage collection or flushing data) that affects the other listeners, but this is the exception rather than the rule.

每個事件來源保留一份針對它傳送至事件的事件接聽程式。Each event source keeps a list of event listeners that it sends events to. 一組篩選準則是每個事件接聽程式的來源組相關聯。A set of filtering criteria is associated with each event source-listener pair. 這些準則判斷事件目前的事件來源會收到該接聽項。These criteria determine the events that listener will receive for the current event source. 接聽程式上接收的事件其OnEventWritten方法。Listeners receive the events on their OnEventWritten method. 因此,子類別的EventListener必須覆寫這個方法,以進行實用的資料的操作。Therefore, subclasses of EventListener must override this method to do something useful with the data.

建立新的事件來源時,OnEventSourceCreated呼叫方法。When a new event source is created, the OnEventSourceCreated method is called. 每個目前的事件接聽程式都會獲得一個OnEventSourceCreated呼叫可將其傳送每個目前事件來源的記錄訊息。Every current event listener gets exactly one OnEventSourceCreated call for every current event source that can send it log messages. 當事件接聽程式建立時,一系列的OnEventSourceCreated通知之前已建立接聽程式的所有事件來源的新接聽程式進行呼叫。When an event listener is created, a series of OnEventSourceCreated calls are made to notify the new listener of all the event sources that existed before the listener was created.

建構函式

EventListener() EventListener() EventListener() EventListener()

建立 EventListener 類別的新執行個體。Creates a new instance of the EventListener class.

方法

DisableEvents(EventSource) DisableEvents(EventSource) DisableEvents(EventSource) DisableEvents(EventSource)

停用指定之事件來源的所有事件。Disables all events for the specified event source.

Dispose() Dispose() Dispose() Dispose()

EventListener 類別的目前執行個體所使用的資源釋出。Releases the resources used by the current instance of the EventListener class.

EnableEvents(EventSource, EventLevel) EnableEvents(EventSource, EventLevel) EnableEvents(EventSource, EventLevel) EnableEvents(EventSource, EventLevel)

啟用具有指定詳細等級或更低之指定事件來源的事件。Enables events for the specified event source that has the specified verbosity level or lower.

EnableEvents(EventSource, EventLevel, EventKeywords) EnableEvents(EventSource, EventLevel, EventKeywords) EnableEvents(EventSource, EventLevel, EventKeywords) EnableEvents(EventSource, EventLevel, EventKeywords)

啟用具有指定詳細等級或更低且符合關鍵字旗標之指定事件來源的事件。Enables events for the specified event source that has the specified verbosity level or lower, and matching keyword flags.

EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>) EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>) EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>) EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>)

啟用具有指定詳細等級或更低且符合關鍵字旗標及引數之指定事件來源的事件。Enables events for the specified event source that has the specified verbosity level or lower, matching event keyword flag, and matching arguments.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
EventSourceIndex(EventSource) EventSourceIndex(EventSource) EventSourceIndex(EventSource) EventSourceIndex(EventSource)

取得小的非負數,其代表指定的事件來源。Gets a small non-negative number that represents the specified event source.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnEventSourceCreated(EventSource) OnEventSourceCreated(EventSource) OnEventSourceCreated(EventSource) OnEventSourceCreated(EventSource)

當事件接聽程式已建立且新事件來源已附加至接聽程式時,針對所有現有的事件來源來呼叫。Called for all existing event sources when the event listener is created and when a new event source is attached to the listener.

OnEventWritten(EventWrittenEventArgs) OnEventWritten(EventWrittenEventArgs) OnEventWritten(EventWrittenEventArgs) OnEventWritten(EventWrittenEventArgs)

每當事件由事件接聽程式已啟用事件的事件來源寫入時呼叫。Called whenever an event has been written by an event source for which the event listener has enabled events.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

事件

EventSourceCreated EventSourceCreated EventSourceCreated EventSourceCreated

發生於將事件來源 (EventSource 物件) 附加至發送器時。Occurs when an event source (EventSource object) is attached to the dispatcher.

EventWritten EventWritten EventWritten EventWritten

發生於事件已由事件接聽程式已啟用事件的事件來源 (EventSource 物件) 寫入時。Occurs when an event has been written by an event source (EventSource object) for which the event listener has enabled events.

適用於