using System.Threading.Tasks;
public static void Main()
Console.WriteLine("Hello World");
record NotificationEvent(DateTime NotificationDate, string NotificationMessage);
public string PublisherName { get; private set; }
public int NotificationInterval { get; private set; }
public delegate void Notify(Publisher p, NotificationEvent e);
public event Notify OnPublish;
public Publisher(string _publisherName, int _notificationInterval){
PublisherName = _publisherName;
NotificationInterval = _notificationInterval;
Thread.Sleep(NotificationInterval);
NotificationEvent notificationObj = new NotificationEvent(DateTime.Now, "New Notification Arrived from");
OnPublish(this, notificationObj);
public string SubscriberName { get; private set; }
public Subscriber(string _subscriberName){
SubscriberName = _subscriberName;
public void Subscribe(Publisher p){
p.OnPublish += OnNotificationReceived;
public void Unsubscribe(Publisher p){
p.OnPublish -= OnNotificationReceived;
protected virtual async void OnNotificationReceived(Publisher p, NotificationEvent e){
await Task.Delay(TimeSpan.FromSeconds(1));
Console.WriteLine("Hey " + SubscriberName + ", " + e.NotificationMessage +" - "+ p.PublisherName + " at " + e.NotificationDate);