Hello
I am writing a class Test. I considered a field “int age” to see how long each instance of this class has been created. In other words i want to know the age of each instantiated object of this class. I assumed i should use the Timer class. I wrote the following piece of code but it did not work. I am not sure if my approach is correct . I really appreciate any help.
Class Test
{
private System.Timers.Timer timerClock = new System.Timers.Timer();
static int age= 0;
public Test()
{
this.timerClock.Elapsed += new System.Timers.ElapsedEventHandler(process);
this.timerClock.Interval = 1000;
this.timerClock.Enabled = true;
}
static void process(Object myObject, EventArgs myEventArgs)
{
age+= 1;
}
}