I created a class that implements a System.Timers.Timer with an elapse event.
private void ElapseEvent(object source, ElapsedEventArgs e){
//read from serial port device
}
In the main program I have a private List<MyTimerClass> _timers.
I dynamically start the timer and add it to the timer list.
var timer1= new MyTimerClass();
timer1.Execute("Device A");
_timers.Add(timer1);
var timer2= new MyTimerClass();
timer2.Execute("Device B");
_timers.Add(timer2);
When the ElapseEvent encounters an error and the serial port was disconnected, I want to remove the timer from the List. How can I possibly do that?
You can add a OnError Method at the class that contains the timers. In order to let the parent class know that an error occurs. Something like the following:
At MyTimerClass
At the parent class: