Пример #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");
 }