Beispiel #1
0
        /// <summary>
        /// 多订阅收到多条返回值
        /// </summary>
        private static void MainMutiSubcriber1()
        {
            Publisher4 publisher  = new Publisher4();
            Subcriber1 subcriber1 = new Subcriber1();
            Subcriber2 subcriber2 = new Subcriber2();
            Subcriber3 subcriber3 = new Subcriber3();

            publisher.GeneralEvent += new GeneralEventHandler(subcriber1.DoChanged);
            publisher.GeneralEvent += new GeneralEventHandler(subcriber2.DoChanged);
            publisher.GeneralEvent += new GeneralEventHandler(subcriber3.DoChanged);
            List <string> list = publisher.DoTask();

            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 多订阅收到一条返回值
        /// </summary>
        private static void MainMutiSubcriber()
        {
            Publisher1 publisher  = new Publisher1();
            Subcriber1 subcriber1 = new Subcriber1();
            Subcriber2 subcriber2 = new Subcriber2();
            Subcriber3 subcriber3 = new Subcriber3();

            publisher.GeneralEvent += new GeneralEventHandler(subcriber1.DoChanged);
            publisher.GeneralEvent += new GeneralEventHandler(subcriber2.DoChanged);
            publisher.GeneralEvent += new GeneralEventHandler(subcriber3.DoChanged);
            publisher.DoTask();

            //Publishser2 publishser2 = new Publishser2();
            //publishser2.Register(new GeneralEventHandler(subcriber1.DoChanged));

            //Publishser3 publishser3 = new Publishser3();
            //publishser3.NumberChanged += subcriber1.DoChanged;
            //publishser3.NumberChanged -= subcriber1.DoChanged;
        }