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 869699
In Process

The Archive Base Latest Questions

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

I am working with two timers: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;

  • 0

I am working with two timers:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace example
{
    public partial class Form1 : Form
    {
        int i = 0;
        int j = 0;
        public Form1()
        {
            InitializeComponent();
            timer1.Interval = 3000;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            i++;
            timer2.Enabled = true;
            if (i < 3)
                time1(i);
            else
                timer1.Enabled = false;


        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            j++;
            timer2.Interval = timer1.Interval / 5;
            if (j < 5)
                time2(j);
            else
                timer2.Enabled = false;

        }

        private void time1(int i)
        {

            MessageBox.Show(i.ToString(), "First Timer");
        }

        private void time2(int j)
        {
            MessageBox.Show(j.ToString(), "SecondTimer");
        }
    }
}

when running this program it gives an output like this:

firsttimer:1
secondTimer:1
secondTimer:2
secondTimer:3
secondTimer:4
firsttimer:2

in message box.

But when debugging, debug cannot move in that order. After finished the secondtimer:2 it goes back to first timer. But I need to debug in the same order like without breakpoints.
I need for this in another application. Why does this happen?

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

    The problem is, that the underlying timer will continue execution even when you stopped your program with a breakpoint. The System.Windows.Forms.Timer you are using will trigger one more event (while a System.Timers.Timer will continue to trigger a lot of events). You can try it on your own:

    Set a timer to an interval of e.g. 3000ms and set a breakpoint into its eventhandler:

    private void timer1_Tick( object sender, EventArgs e )
    {
        // insert breakpoint here
    }
    

    Wait ~3 seconds before you continue your program. The eventhandler will be called immediately again. The next time wait longer (~10 seconds), same result – the eventhandler will be triggered once immediately, then after ~three seconds. Compare the behaviour to System.Timers.Timer, which will trigger the event in your second testcase more than once.

    So, depending on your breakpoint (do you set it in timer1_Tick before timer2.Enabled = true; or after?) and on the time you stop your program before continuing execution you will get different results.

    Unfortunatly there is nothing you can do. In your special case you could stop all timers before setting a breakpoint, like:

    private static void Break()
    {
        var timer1Enabled = timer1.Enabled;
        var timer2Enabled = timer2.Enabled;
        timer1.Stop();
        timer2.Stop();
        // insert breakpoint here
        timer1.Enabled = timer1Enabled;
        timer2.Enabled = timer2Enabled;
    }
    

    but that would restart the timers and the proportion between the timer1 and timer2 intervals would be wrong.

    For more informations about the timers of .net you can read this article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on maintaining someone else's code that is using multithreading, via two
I would like to using two times @model to get data from another part
I am working with google app engine and using the low leval java api
I am using ColdFusion 9.1.0. I am working on part of a site that
I've been using jedie's python ping implementation on Windows. I could be wrong, but
I am working on this problem for two days and this is driving me
I am working on a project in C#.NET using the .NET framework version 3.5.
I'm currently developing application using DirectSound for communication on an intranet. I've had working
I'm working on a web application for Apache Tomcat. I'm using a class called
I am currently working on a school system where we have a parent course

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.