Example #1
0
        // This will be the starting point of our event-- it will create FireEventArgs,
        // and then raise the event, passing FireEventArgs.
        public void ActivateFireAlarm(string room, int ferocity)
        {
            FireEventArgs fireArgs = new FireEventArgs(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.
            FireEvent(this, fireArgs);
        }
Example #2
0
        // This is the function to be executed when a fire event is raised.
        void ExtinguishFire(object sender, FireEventArgs fe)
        {
            Console.WriteLine("\nThe ExtinguishFire function was called by {0}.", sender.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);
        }