When I start the thread do not even change the images before I get to the sleep, how do I put the thread correctly, or what change do I need to make it work?
using System;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
namespace semaforo_hilos_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int c = 1;
public void Go()
{
for (int i = 1; i <= 10; i++)
{
if (c == 1)
{
pictureBox1.Image = Properties.Resources.gris;
pictureBox2.Image = Properties.Resources.gris;
pictureBox3.Image = Properties.Resources.verde;
c = 2;
Thread.Sleep(3000);
}
if (c == 2)
{
pictureBox1.Image = Properties.Resources.gris;
pictureBox2.Image = Properties.Resources.amarillo;
pictureBox3.Image = Properties.Resources.gris;
c = 3;
Thread.Sleep(3000);
}
if (c == 3)
{
pictureBox1.Image = Properties.Resources.rojo;
pictureBox2.Image = Properties.Resources.gris;
pictureBox3.Image = Properties.Resources.gris;
c = 1;
Thread.Sleep(3000);
}
}
}
public void Form1_Load(object sender, EventArgs e)
{
Form1 obj = new Form1();
Thread t1 = new Thread(new ThreadStart(obj.Go));
t1.Start();
}
}
}