Information Technology Reference
In-Depth Information
public class MyTimerClass { ... }
class ClassA {
public void TimerHandlerA(object obj, EventArgs e) // Event handler
{ Console.WriteLine("Class A handler called"); }
}
class ClassB {
public static void TimerHandlerB(object obj, EventArgs e) // Static
{ Console.WriteLine("Class B handler called"); }
}
class Program {
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(2000);
}
}
This code produces the following output:
Class A handler called
Class B handler called
Class A handler called
Class B handler called
Search WWH ::




Custom Search