What happens if I call Start () twice in the System.Windows.Forms.Timer class?

Imagine what I have System.Windows.Forms.Timerwith an interval of 1000 ms.

If I call the method Timer.Start()and call again after 500 ms Timer.Start(), what happens? The second call Startwill reset the interval or not? Are there any side effects?

+3
source share
3 answers

The timer is already running, so the second call will not affect it.

Regardless, it is easy to test.

+8
source

Start() Enabled true. Enabled true, Enabled true .

, Stop() Enabled false.

+2

It will not affect anything ...

See this code

  class TimerTest
{
   static int i = 0;
    static void Tick(object sender, EventArgs e)
    {

        Console.WriteLine(i);
        i++;
    }
    static void Main()
    {
        // interval = 500ms
        Timer tmr = new Timer();
        tmr.Interval = 500;
        tmr.Elapsed += Tick;
        tmr.Start();
        Console.ReadLine();
        tmr.Start();
        Console.ReadLine();
        tmr.Stop();
        Console.ReadLine();
        tmr.Start();
        Console.ReadLine();
        tmr.Dispose(); // This both stops the timer and cleans up.
    }
}

after starting u, if Enter return, the second start will not affect anything.

+2
source

Source: https://habr.com/ru/post/1782446/


All Articles