Click here to Skip to main content
12,948,566 members (62,943 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
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
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)
           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)
       private void timer2_Tick(object sender, EventArgs e)
           textBox1.Text = textBox1.Text + Environment.NewLine + "Timer2 Enabled at " + DateTime.Now.ToString();

Interval of timer1 is 1000 and timer2 is 4000.
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
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.

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
OriginalGriff 5,419
CHill60 3,275
Maciej Los 2,778
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web01 | 2.8.170524.1 | Last Updated 20 Jun 2014
Copyright © CodeProject, 1999-2017
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