Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Timer.stop();

$
0
0

I made a button in visual studio that once pressed, start a timer and set the interval between the tick event,  in this way

private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
            timer1.Interval = 2000;
        }


in the timer tick event I want a message to appear as soon as the timer reaches the tick, and so it does :

private void timer1_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("Ticked");
            timer1.Stop();
        }

But if I call the time.stop method after the messagebox line, it simply won't work. It does if I put it before.. May someone explain me why ?

Another short question : it seems to wait a bit more than 2 secs to start the first tick, all the others after the first one seems nice.. Am I missing something ?


Viewing all articles
Browse latest Browse all 31927


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>