Event Inheritance for Classes Derived from BaseEvent

When developers want to expose application events through WMI, the events must be derived from the WMI system class __ExtrinsicEvent. For more information, see "__ExtrinsicEvent" in the Windows Management Instrumentation documentation in the MSDN Library at https://msdn.microsoft.com/library. By default, when you derive a class from the BaseEvent class in the System.Management.Instrumentation namespace, your managed class represents a WMI class derived from __ExtrinsicEvent.

The following code example shows how to use inheritance to create a simple WMI event hierarchy using the BaseEvent helper class. The top-level managed event class, TopEvent, is represented by a WMI class, TopEvent, derived from __ExtrinsicEvent. The TopEvent class will have two children, Branch1Event and Branch2Event. Finally, there will be two children of Branch1Event (Leaf1AEvent and Leaf1BEvent), and one child of Branch2Event (Leaf2AEvent).

To visualize this event hierarchy, you can examine the diagram in the first comment block of the example. For reference, the most derived classes in a hierarchy (the classes that do not have any further derived classes) are referred to as leaf nodes. For event hierarchies, leaf nodes do not have any particular importance, but the distinction between leaf nodes and non-leaf nodes plays an important role for instance instrumentation. For simplicity, the events do not have any properties. In practice, you would most likely be extending each child class with additional properties, but in the following code, this is omitted to keep the example short.

Imports System
Imports System.Management.Instrumentation

<Assembly: Instrumented()> 

' A simple tree of events derived from BaseEvent
' TopEvent--Branch1Event--Leaf1AEvent
'          \            \-Leaf1BEvent
'           \
'            Branch2Event--Leaf2AEvent
' Any event in the hierarchy can be raised by the application

' This class inherits the 'InstrumentationType.Event' attribute
' from 'BaseEvent'
<InstrumentationClass(InstrumentationType.Event)> _
Public Class TopEvent
    Inherits BaseEvent

End Class

' This class inherits the 'InstrumentationType.Event' attribute
Public Class Branch1Event
    Inherits TopEvent

End Class

' This class inherits the 'InstrumentationType.Event' attribute
Public Class Leaf1AEvent
    Inherits Branch1Event

End Class

' This class inherits the 'InstrumentationType.Event' attribute
Public Class Leaf1BEvent
    Inherits Branch1Event

End Class

' This class inherits the 'InstrumentationType.Event' attribute
Public Class Branch2Event
    Inherits TopEvent

End Class

' This class inherits the 'InstrumentationType.Event' attribute
Public Class Leaf2AEvent
    Inherits Branch2Event

End Class

Class App

    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        ' Raise each type of event
        Dim event1 As New TopEvent
        event1.Fire()
        Dim event2 As New Branch1Event
        event2.Fire()
        Dim event3 As New Leaf1AEvent
        event3.Fire()
        Dim event4 As New Leaf1BEvent
        event4.Fire()
        Dim event5 As New Branch2Event
        event5.Fire()
        Dim event6 As New Leaf2AEvent
        event6.Fire()

    End Function
End Class
using System;
using System.Management.Instrumentation;

[assembly:Instrumented]

// A simple tree of events derived from BaseEvent
// TopEvent--Branch1Event--Leaf1AEvent
//          \            \-Leaf1BEvent
//           \
//            Branch2Event--Leaf2AEvent
// Any event in the hierarchy can be raised by the application

// This class inherits the 'InstrumentationType.Event' attribute
// from 'BaseEvent'
public class TopEvent : BaseEvent {
}

// This class inherits the 'InstrumentationType.Event' attribute
public class Branch1Event : TopEvent{
}

// This class inherits the 'InstrumentationType.Event' attribute
public class Leaf1AEvent : Branch1Event {
}

// This class inherits the 'InstrumentationType.Event' attribute
public class Leaf1BEvent : Branch1Event {
}

// This class inherits the 'InstrumentationType.Event' attribute
public class Branch2Event : TopEvent {
}

// This class inherits the 'InstrumentationType.Event' attribute
public class Leaf2AEvent : Branch2Event {
}

class App {
    static void Main(string[] args) {
        // Raise each type of event
        new TopEvent().Fire();
        new Branch1Event().Fire();
        new Leaf1AEvent().Fire();
        new Leaf1BEvent().Fire();
        new Branch2Event().Fire();
        new Leaf2AEvent().Fire();
    }
}

See Also

Tasks

How to: Create an Event Class by Deriving from BaseEvent

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.