Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:35:30+00:00 2026-05-23T08:35:30+00:00

I created a class that implements a System.Timers.Timer with an elapse event. private void

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:35:30+00:00Added an answer on May 23, 2026 at 8:35 am

    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

    public MyTimerClass(Action<MyTimerClass, Exception> onError)
    {
        this.onError = onError;
    }
    
    private void ElapseEvent(object source, ElapsedEventArgs e){
    try{
    //read from serial port device
    }
    catch(Exception ex) // It would be better if you know the exceptions you want to handle
    {
      if(this.onError != null)
      {
       this.onError(this, ex);
      }
    }
    }
    

    At the parent class:

    var timer1= new MyTimerClass(this.OnTimerError);
     timer1.Execute("Device A");
    _timers.Add(timer1);
    
     var timer2= new MyTimerClass(this.OnTimerError);
     timer2.Execute("Device B");
    _timers.Add(timer2);
    
    
    
    public void OnTimerError(MyTimerClass timer, Exception error)
    {
     //Log the exception
      _timers.Remove(timer);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created class that takes Exception type in constructor private readonly Exception _exception; public
I am using System.Timers.Timer class in one of the classes in my application. I
I have a class that creates and uses a System.Threading.Timer, something like this: using
I am trying to create a class that implements the IUnknown interface. I have
Class someInterface = Class.fromName(some.package.SomeInterface); How do I now create a new class that implements
I created a class that's something like this: public class MovieTheaterList { public DateTime
I created a class that handles serial port asynchronously. I use it to communicate
I created a class that extends ProfileBase: public class CustomerProfile : ProfileBase { public
I created a simple class that shows what I am trying to do without
I've created a Java class that connects to an IIS website requiring NTLM authentication.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.