예제 #1
0
 public void Add(int x)
 {
     total += x;
     if (total > mThreshold)
     {
         ThresholdReachedEventArgs args = new ThresholdReachedEventArgs
         {
             Threshold = mThreshold,
             TimeReached = DateTime.Now
         };
         OnThresholdReached(args);//invoke event handler
     }
 }
예제 #2
0
        protected virtual void OnThresholdReached(ThresholdReachedEventArgs e)
        {
            EventHandler<ThresholdReachedEventArgs> handler = ThresholdReached;
            if (handler != null)
            {
                Array.ForEach<Delegate>(handler.GetInvocationList(), (item) =>
                {
                    try
                    {
                        item.DynamicInvoke(this, e);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });

                //handler(this, e);
            }
        }
예제 #3
0
 static void counter_Threshold2(object sender, ThresholdReachedEventArgs e)
 {
     Console.WriteLine("The threshold of {0} was reached at {1}.", e.Threshold, e.TimeReached);
 }
예제 #4
0
 static void counter_Threshold(object sender, ThresholdReachedEventArgs e)
 {
     Console.WriteLine("The threshold of {0} was reached at {1}.", e.Threshold, e.TimeReached);
     throw new ArgumentException("e");
 }