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

  • SEARCH
  • Home
  • 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 4334386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:31:19+00:00 2026-05-21T10:31:19+00:00

My application looks like this: I have an MDI parent form – form1, the

  • 0

My application looks like this:

I have an MDI parent form – form1, the form that starts and stops the timer – form 2, and a timerCalls class with all the timer logic.

Form1 code:

TimerCalls timerCalls = new TimerCalls();

public SMS()
{
    InitializeComponent();
    timerCalls.InitializeTimer();
}

Form2 code:

TimerCalls timerCalls = new TimerCalls();

public Form2()
{
    InitializeComponent();
}

private void btnSendOn_Click(object sender, EventArgs e)
{
    timerCalls.sendTimer.Start();
}

private void btnSendOff_Click(object sender, EventArgs e)
{
    timerCalls.sendTimer.Stop();
}

TimerCalls class code:

class TimerCalls
{
    public System.Timers.Timer sendTimer = new System.Timers.Timer();
    public System.Timers.Timer recTimer = new System.Timers.Timer();

    public void InitializeTimer()
    {
        // Send timer
        sendTimer.Elapsed += new ElapsedEventHandler(sendProcessTimerEvent);
        sendTimer.Interval = 3000;
        //rec timer
        recTimer.Elapsed += new ElapsedEventHandler(recProcessTimerEvent);
        recTimer.Interval = 3000;
    }

    private void sendProcessTimerEvent(object sender, EventArgs e)
    {
        MessageBox.Show("Send 3 sec");
    }

    private void recProcessTimerEvent(object sender, EventArgs e)
    {
        MessageBox.Show("Rec 3 sec");
    }
}

This is the problem: I open form2, start the timer, close form2, open it again and try to stop the timer it doesn’t stop it. Once I reopen the form2, all I can do is start and stop a new timer, but the previous one is still running. Everything works fine (timer starting and stopping) until I close form2. If the timer was on when I closed the form I can’t stop it once I open the form2 again.

How can I fix this?

  • 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-21T10:31:20+00:00Added an answer on May 21, 2026 at 10:31 am

    Assuming you are closing the form, and then creating a new one then yes, it will create multiple instances of Form2.

    The best approach as suggested by others would be to use a singleton pattern for TimerCalls and just get the instance in your Form2.

    If this sounds like too much work, simply hide Form2 instead of closing it:

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason != CloseReason.UserClosing)
            return;
        e.Cancel = true;
        Hide();
    }
    

    Then just make sure when you click the button to reopen Form2, you just show the previously created one – which will be something like this.

    public class Form1 : Form
    {
        private Form2 mForm2;
    
        protected void OpenForm2_Click(object sender, EventArgs e)
        {
           if (mForm2 == null)  
               mForm2 = new Form2();
           mForm2.Show();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rack application that looks like this: class Foo def initialize(app) @app
In our application we have a little query that looks like this: var selectedAgents
I have a markdown helper that looks like this in application_helper.rb . How would
I have a rails helper in my application_helper.rb file that looks like this: def
I'm developing an application on Glassfish 3. I have an EJB that looks like
So, I have a REST application and looks like this: @GET @Produces(MediaType.APPLICATION_JSON) @Path(/getpartners) public
I currently have a partial-application function which looks like this: Function.prototype.curry = function() {
I have simple web application based on JSP. Root of application looks like this:
I created a route in ASP.net MVC application that looks like this: routes.MapRoute( ArticleRoute,
I am developing an application that draws map. Currently my logic looks like this:

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.