//publish function publishes a Notification Event public void Publish() { while (true) { // fire event after certain interval Thread.Sleep(NotificationInterval); if (OnPublish != null) { NotificationEvent notificationObj = new NotificationEvent(DateTime.Now, "New Notification Arrived from"); OnPublish(this, notificationObj); } Thread.Yield(); } }
// It get executed when the event published by the Publisher protected virtual void OnNotificationReceived(Publisher p, NotificationEvent e) { Console.WriteLine("Hey " + SubscriberName + ", " + e.NotificationMessage + " - " + p.PublisherName + " at " + e.NotificationDate); }