Click here to Skip to main content
12,400,556 members (55,209 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
I have two timers in a windows form app.

I want first timer1 to enable by button1 click.

What i want to know is how to do following:

The first timer1 must fire once(tick once).

And the second timer2 to start after 20 seconds of timer1 tick.

Thank you.
Posted 19-Jun-14 21:13pm
Updated 19-Jun-14 21:21pm
Kim Togo26.9K
v2
Comments
DamithSL 20-Jun-14 3:22am
   
can you update the question with the code that you tried so far?
Prasad Avunoori 20-Jun-14 3:27am
   
Do you want both timers should fire only once?
Member 10579673 20-Jun-14 3:44am
   
No the timer1 must fire once and after 20 seconds after Timer1 tick timer2 must start.interval of timer2 is 4000.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

1. Start the second timer in timer1 after 20 seconds using sleep() method.
2. Stop the timer1 in timer2.

int count = 1;
 
       private void button1_Click(object sender, EventArgs e)
       {
           timer1.Start();
           textBox1.Text = "Button1 Clicked at " + DateTime.Now.ToString();
 
       }
 
       private void timer1_Tick(object sender, EventArgs e)
       {
           if (count == 1)
           {
               textBox1.Text = textBox1.Text + Environment.NewLine + "Timer1 Enabled at " + DateTime.Now.ToString();
           }
 
           if (count == 17)
           {
               timer2.Start();
           }
           count++;
       }
 
       private void timer2_Tick(object sender, EventArgs e)
       {
           timer1.Stop();
           textBox1.Text = textBox1.Text + Environment.NewLine + "Timer2 Enabled at " + DateTime.Now.ToString();
 
       }
   }


Interval of timer1 is 1000 and timer2 is 4000.
  Permalink  
v3
Comments
Member 10579673 20-Jun-14 3:41am
   
@Prasad Avunoori can ya please elaborate?
Prasad Avunoori 20-Jun-14 5:10am
   
View my updated solution.
Kim Togo 20-Jun-14 6:59am
   
My vote of 1.
"System.Threading.Thread.Sleep(20000);" it freezes the whole UI!

It will make the UI unresponsive for 20 sec.
Prasad Avunoori 20-Jun-14 7:53am
   
Please have a look at my v3 of my solution.
Kim Togo 20-Jun-14 7:56am
   
That is much better.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

A good start is to look at the Timer Class[^] and see the examples. It will give you a good idea on how-to make it work.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 20 Jun 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100