Example #1
0
        protected virtual void OnThresholdReached(ThresholdReachedEventArgs e)
        {
            //the hander receives the method binded  int the instance of the delegate
            EventHandler <ThresholdReachedEventArgs> handler = ThresholdReached;

            if (handler != null)
            {
                //invoke the delegate passing the Counther class and the EventArgs
                handler(this, e);
            }
        }
Example #2
0
        public void Add(int x)
        {
            total += x;
            if (total >= threshold)
            {
                ThresholdReachedEventArgs args = new ThresholdReachedEventArgs();
                args.Threshold   = threshold;
                args.TimeReached = DateTime.Now;

                //pass the values to event handler
                OnThresholdReached(args);
            }
        }
Example #3
0
 static void c_ThresholdReached(object sender, ThresholdReachedEventArgs e)
 {
     Console.WriteLine("The threshold of {0} was reached at {1}.", e.Threshold, e.TimeReached);
     Environment.Exit(0);
 }