Search code examples
c#timerseconds

Timer Interval 1000 != 1 second?


I have a label which should show the seconds of my timer (or in other word I have a variable to which is added 1 every interval of the timer). The interval of my timer is set to 1000, so the label should update itself every second (and should also show the seconds). But the label is after 1 second already in the hundreds. What is a proper interval to get 1 second?

int _counter = 0;
Timer timer;

timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(TimerEventProcessor);
label1.Text = _counter.ToString();
timer.Start();

private void TimerEventProcessor(object sender, EventArgs e)
{
  label1.Text = _counter.ToString();
  _counter += 1;
}

Solution

  • The proper interval to get one second is 1000. The Interval property is the time between ticks in milliseconds:

    MSDN: Timer.Interval Property

    So, it's not the interval that you set that is wrong. Check the rest of your code for something like changing the interval of the timer, or binding the Tick event multiple times.