static void Main() { ClassA ca = new ClassA(); MyTimerClass mc = new MyTimerClass(); mc.Elapsed += // Register handler. new EventHandler <MyTCEventArgs>(ca.TimerHandlerA); Thread.Sleep(3250); }
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); }
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. }