Ejemplo n.º 1
0
        public event EventHandler <SomeObjectEventArgs> Published; //in case we need to send addtional data to event

        //public event EventHandler Published; // in case we don't need to send addtional data to event

        public void DoSomethingInPublisherClass(SomeObject someObject)
        {
            Console.WriteLine("There is some work in  <DoSomethingInPublisherClass method>, please wait...");
            Thread.Sleep(3000);

            //raise the event:
            OnPublished(someObject);
        }
Ejemplo n.º 2
0
 //raise the event:
 protected virtual void OnPublished(SomeObject someObject)
 {
     if (Published != null)
     {
         Published(this, new SomeObjectEventArgs()
         {
             Title = someObject
         });
     }
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var someObject = new SomeObject()
            {
                Title = "Object 1"
            };
            var publisher     = new Publisher();
            var subscriber_01 = new Subscriber_01();
            var subscriber_02 = new Subscriber_02();

            //linking event from publisher with method from subscrriber.
            publisher.Published += subscriber_01.OnPublished;
            publisher.Published += subscriber_02.OnPublished;


            publisher.DoSomethingInPublisherClass(someObject);


            Console.ReadKey();
        }