Exemple #1
0
        // This will be the starting point of our event-- it will create FireEventArgs,
        // and then raise the event, passing FireEventArgs.
        public void ActivateFireAlarmHandlerTrigger(string room, int ferocity)
        {
            FireAlarmEventArgs fireArgs = new FireAlarmEventArgs(room, ferocity);

            // Now, raise the event by invoking the delegate. Pass in
            // the object that initated the event (this) as well as FireEventArgs.
            // The call must match the signature of FireEventHandler.
            FireAlarmEventHandlerPtr(this, fireArgs);
        }
Exemple #2
0
        // This is the function to be executed when a fire event is raised.
        void ExtinguishFire(object sender, FireAlarmEventArgs fe)
        {
            Console.WriteLine("\nThe ExtinguishFire function was called by {0} with ferocity {1}.",
                              sender.ToString(), fe.ferocity.ToString());

            // Now, act in response to the event.
            if (fe.ferocity < 2)
            {
                Console.WriteLine("This fire in the {0} is no problem.  I'm going to pour some water on it.", fe.room);
            }
            else if (fe.ferocity < 5)
            {
                Console.WriteLine("I'm using FireExtinguisher to put out the fire in the {0}.", fe.room);
            }
            else
            {
                Console.WriteLine("The fire in the {0} is out of control.  I'm calling the fire department!", fe.room);
            }
        }