//create a function to check if event is released, and handle that event with the help of event handler public void NewPost() { while (true) { Thread.Sleep(3000); // create event after every 3 second if (Event != null) { BroadCast bc = new BroadCast(); bc.BroadCast_Date = DateTime.Now; bc.BroadCast_Message = "New Article has been Published.."; Event(this, bc); } } }
void P_Event(Publisher P, BroadCast e) // It get executed when the event released by the Publisher { Console.WriteLine("Hey " + s + ", Message from " + P.PublisherName + " at " + e.BroadCast_Date + " — " + e.BroadCast_Message); }