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); } } }
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); } }
public static void DoSomething(object sender, TotalEventArgs e) { Console.WriteLine("Threshold was reached with value : {0}", e.currentValue); }