Cuando inicio el hilo ni siquiera cambian las imágenes antes de que llegue al sleep, como pongo correctamente el hilo, o que cambio necesito hacer para que funcione?
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();
}
}
}