//OnThresholdReach method protected virtual void OnThresholdReach(ThresholdReachedEventArgs e) { EventHandler<ThresholdReachedEventArgs> handler = ThresholdReached; if (handler != null) { handler(this, e); } }
//Add method public void Add(int x) { totoal += x; if (totoal >= threshold) { //event object named args ThresholdReachedEventArgs args = new ThresholdReachedEventArgs(); //Threshold is the args object's proterty args.Threshold = threshold; //TimeReached is the args object's proterty args.TimeReached = DateTime.Now; OnThresholdReach(args); } }
static void c_ThresholdReached(object sender, ThresholdReachedEventArgs e) { Console.WriteLine("The inventory reached the REORDER LEVEL: {0} at {1}. \nPlease order more cars now!" , e.Threshold, e.TimeReached); }