static void Main(string[] args) { string data = "some data"; var publihser = new Publihser(); publihser.SomethingHappened += (s, m) => { Console.WriteLine($"consumer1: {m} Data:{data}"); }; publihser.SomethingHappened += (s, m) => { Console.WriteLine("consumer2: " + m); }; Register(publihser); publihser.ReportEvent("Winter is coming"); GC.Collect(); publihser.ReportEvent("another message"); Console.ReadLine(); }
private static void Register(Publihser publihser) { var consumer = new Consumer(); publihser.SomethingHappened += consumer.Print; }