예제 #1
0
        static void Main()
        {
            ClassA       ca = new ClassA();
            MyTimerClass mc = new MyTimerClass();

            mc.Elapsed +=                                            // Register handler.
                          new EventHandler <MyTCEventArgs>(ca.TimerHandlerA);
            Thread.Sleep(3250);
        }
예제 #2
0
        static void Main()
        {
            ClassA       ca = new ClassA();                             // Create the class object.
            MyTimerClass mc = new MyTimerClass();                       // Create the timer object.

            mc.Elapsed += ca.TimerHandlerA;                             // Add handler A -- instance.
            mc.Elapsed += ClassB.TimerHandlerB;                         // Add handler B -- static.

            Thread.Sleep(2250);
        }
예제 #3
0
        static void Main()
        {
            ClassA       ca = new ClassA();                             // Create the class object.
            MyTimerClass mc = new MyTimerClass();                       // Create the timer object.

            mc.Elapsed += ca.TimerHandlerA;                             // Add handler A -- instance.
            mc.Elapsed += ClassB.TimerHandlerB;                         // Add handler B -- static.

            Thread.Sleep(2250);

            mc.Elapsed -= ClassB.TimerHandlerB;                         // Remove static handler B.

            Console.WriteLine("Class B event handler removed");
            Thread.Sleep(2250);                                         // Sleep more than 2 seconds.
        }