// Create a FireAlarm to handle and raise the fire events. public FireAlarmHandlerListener(FireAlarmEventEnabledClass fireAlarm) { // Add a delegate containing the ExtinguishFire function to the class' // event so that when FireAlarm is raised, it will subsequently execute // ExtinguishFire. fireAlarm.FireAlarmEventHandlerPtr += new FireAlarmEventEnabledClass.FireAlarmEventHandler(ExtinguishFire); }
public static void Main() { // Create an instance of the class that will be firing an event. FireAlarmEventEnabledClass myFireAlarm = new FireAlarmEventEnabledClass(); // Create an instance of the class that will be handling the event. Note that // it receives the class that will fire the event as a parameter. FireAlarmHandlerListener myFireHandlerListener = new FireAlarmHandlerListener(myFireAlarm); //use our class to raise a few events and watch them get handled myFireAlarm.ActivateFireAlarmHandlerTrigger("Kitchen", 3); myFireAlarm.ActivateFireAlarmHandlerTrigger("Study", 1); myFireAlarm.ActivateFireAlarmHandlerTrigger("Porch", 5); Console.ReadLine(); }