private static void Escenario1() { Publisher g = new Publisher("Big Generator"); Suscriber s1 = new Suscriber("Suscriber1"); g.NewNumberEvent += s1.MyEventHandler; Suscriber s2 = new Suscriber("Suscriber2"); g.NewNumberEvent += s2.MyEventHandler; g.Publish(); }
static void Main(string[] args) { Publisher g = new Publisher("Big Generator"); Suscriber s1 = new Suscriber("Suscriber1"); g.GeneratingNumberEvent += s1.MyEventHandler; Suscriber s2 = new Suscriber("Suscriber2"); g.GeneratingNumberEvent += s2.MyEventHandler; g.Run(); g.GeneratingNumberEvent -= s2.MyEventHandler; g.Run(); }
private static void Escenario1() { Publisher g = new Publisher("Big Generator"); Suscriber s1 = new Suscriber("Suscriber1"); g.NewNumberEvent += s1.MyEventHandlerAsync; Suscriber s2 = new Suscriber("Suscriber2"); g.NewNumberEvent += s2.MyEventHandlerAsync; g.Publish(); // Espero un rato para que terminen los eventHandlers asincronicos Thread.Sleep(10000); }
static void Main(string[] args) { Publisher g = new Publisher("Big Generator"); Suscriber s1 = new Suscriber("Suscriber1"); g.GeneratingNumberEvent += s1.MyEventHandler; Suscriber s2 = new Suscriber("Suscriber2"); g.GeneratingNumberEvent += s2.MyEventHandler; g.Run(); Console.WriteLine("----- Suscriber2 se desuscribe ----"); g.GeneratingNumberEvent -= s2.MyEventHandler; g.Run(); }
private static void Escenario1() { Publisher g = new Publisher("Big Generator"); Suscriber s1 = new Suscriber("Suscriber1"); g.GeneratingNumber += s1.MyEventHandler; Suscriber s2 = new Suscriber("Suscriber2"); g.GeneratingNumber += s2.MyEventHandler; g.GenerateNumbers(); Console.WriteLine("\n"); g.GeneratingNumber -= s2.MyEventHandler; g.GenerateNumbers(); }