コード例 #1
0
            public void Add(int input)
            {
                total += input;
                if (total > threshold)
                {
                    EventHandler <TotalEventArgs> handler = event_2;
                    if (handler != null)
                    {
                        TotalEventArgs eventArgs = new TotalEventArgs()
                        {
                            currentValue = total
                        };
                        handler(this, eventArgs);
                    }

                    Mydelegate handler_2 = event_1;
                    if (handler_2 != null)
                    {
                        TotalEventArgs eventArgs = new TotalEventArgs()
                        {
                            currentValue = total
                        };
                        handler_2(this, eventArgs);
                    }
                }
            }
コード例 #2
0
        public virtual void OnTotal(TotalEventArgs e)
        {
            var handler = Total;// Aquí se almacena el valor antes de comparar, para que si se cancela la suscripción no se quede total como nulo y falle el código

            if (null != handler)
            {
                handler(this, e);
            }
        }
コード例 #3
0
 public static void DoSomething(object sender, TotalEventArgs e)
 {
     Console.WriteLine("Threshold was reached with value : {0}", e.currentValue);
 }