示例#1
0
        static void Main(string[] args)
        {
            Publisher pub = new Publisher();
            Subscriber sub1 = new Subscriber("sub1", pub);
            Subscriber sub2 = new Subscriber("sub2", pub);

            // Call the method that raises the event.
            Timer timer = new Timer(30 * 60 * 1000);
        static void Main(string[] args)
        {
            Publisher pub = new Publisher();
            Subscriber sub1 = new Subscriber("sub1", pub);
            Subscriber sub2 = new Subscriber("sub2", pub);

            // Call the method that raises the event.
            pub.DoSomething();

            // Keep the console window open
            Console.WriteLine("Press Enter to close this window.");
            Console.ReadLine();
        }
 public Subscriber(string ID, Publisher pub)
 {
     id = ID;
     // Subscribe to the event using C# 2.0 syntax
     pub.RaiseCustomEvent += HandleCustomEvent;
 }
        static void Main(string[] args)
        {
            Publisher publisherOne = new Publisher();
            Subscriber subscriberOne = new Subscriber("Subscriber one", publisherOne);
            Subscriber subscriberTwo = new Subscriber("Subscriber two", publisherOne);

            // Call the method that raises the event.
            publisherOne.FillList();
        }
 public Subscriber(string ID, Publisher pub)
 {
     id = ID;
     // Subscribe to the event using C# 2.0 syntax
     pub.RaiseCustomEvent += HandleCustomEvent;
 }