2
Answers

C# Code for making a traffic Light System ???

Waqas Ali

Waqas Ali

12y
4.2k
1
Hello Everyone, 
I am new to C# so am having trouble making a Traffic Lights System.
I have used three timers and a button. 
When I press the button the RedTimer starts but the program just stops working after that, the red light remains lit and the other one's don't start( it does respond ) .
This is the code for my three timers and each timer has an interval of 1000 ms.
Can anyone tell me why this is happening ???

This is the code:
    private void buttonStart_Click(object sender, EventArgs e)         {             timerRed.Start();         }           private void timerRed_Tick(object sender, EventArgs e)        {            timerGreen.Stop();            redLight.FillColor = Color.Red;                        greenLight.FillColor = Color.Black;             timerRed.Stop();             timerYellow.Start();         }         private void timerYellow_Tick(object sender, EventArgs e)         {             timerRed.Stop();             yellowLight.FillColor = Color.Yellow;             redLight.FillColor = Color.Black;             timerYellow.Stop();             timerGreen.Start();         }         private void timerGreen_Tick(object sender, EventArgs e)         {             timerGreen.Stop();             greenLight.FillColor = Color.Green;             yellowLight.FillColor = Color.Black;             timerGreen.Stop();             timerRed.Start();         }
Answers (2)