Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int time;

            Console.WriteLine("Enter time value, please");
            time = Convert.ToInt32(Console.ReadLine());

            var firstSubscriber  = new FirstSubscriber();
            var secondSubscriber = new SecondSubscriber();
            var manager          = new MessageManager();

            firstSubscriber.Register(manager);
            manager.SimulateNewMessage(time, "1-st event");

            secondSubscriber.Register(manager);
            manager.SimulateNewMessage(time, "2-nd event");

            firstSubscriber.Unregister(manager);

            var secManager = new MessageManager();

            firstSubscriber.Register(secManager);

            manager.SimulateNewMessage(time, "3-rd event");
            secManager.SimulateNewMessage(time, "4-th event");

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ClockManager clockManager = new ClockManager();

            FirstSubscriber  sub1 = new FirstSubscriber();
            SecondSubscriber sub2 = new SecondSubscriber();

            sub1.Register(clockManager);
            sub2.Register(clockManager);

            clockManager.SimulateTimeOut(5);
            Thread.Sleep(5000);
            clockManager.SimulateTimeOut(3);
            Thread.Sleep(5000);
            sub1.Unregister(clockManager);
            clockManager.SimulateTimeOut(4);


            Console.ReadKey();
        }