Waqas Ali

Waqas Ali

  • NA
  • 19
  • 27.7k

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

Jun 28 2012 8:29 AM
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: 
  1. private void buttonStart_Click(object sender, EventArgs e)  
  2. {   
  3.     timerRed.Start();   
  4. }  
  5. private void timerRed_Tick(object sender, EventArgs e)  
  6. {   
  7.     timerGreen.Stop(); redLight.FillColor = Color.Red; greenLight.FillColor = Color.Black; timerRed.Stop(); timerYellow.Start();   
  8. }  
  9. private void timerYellow_Tick(object sender, EventArgs e)  
  10. {   
  11.     timerRed.Stop(); yellowLight.FillColor = Color.Yellow; redLight.FillColor = Color.Black; timerYellow.Stop(); timerGreen.Start();   
  12. }  
  13. private void timerGreen_Tick(object sender, EventArgs e)  
  14. {   
  15.     timerGreen.Stop(); greenLight.FillColor = Color.Green; yellowLight.FillColor = Color.Black; timerGreen.Stop(); timerRed.Start();   
  16. }  
 

Answers (2)