public void Move() { while(tank.Fuel > 5) { tank.Fuel -= 2; if (tank.Fuel < 5) { TankEmptyEventArgs e = new TankEmptyEventArgs (tank.Fuel); tank.OnTankEmpty (e); } else Console.WriteLine ("Moving... Tank balance is {0}", tank.Fuel); } }
// actually the subscriber public void Stop(object sender, TankEmptyEventArgs e) { Console.WriteLine("Engine has stoppeed. Fuel balance: {0}", e.FuelBalance); }
// method that raise event public void OnTankEmpty(TankEmptyEventArgs e) { if (tankEmpty != null) tankEmpty (this, e); }