Hola, quería hacer un ejemplo muy básico para aprender a manejar distintos hilos, en el cual al pulsar un botón se ejecutaran los dos hilos y vayan apareciendo en 2 textBox una frase para mostrar que se ejecuta ese hilo. Agradecería una ayuda!
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread thread1 = new Thread(new ThreadStart(DisplayThread1));
Thread thread2 = new Thread(new ThreadStart(DisplayThread2));
// start them
thread1.Start();
thread2.Start();
}
void DisplayThread2()
{
string p2 = "Thread 2";
p2 = textBox2.Text;
Thread.Sleep(1000);
}
void DisplayThread1()
{
string p1 = "Thread 1";
p1 = textBox1.Text;
Thread.Sleep(1000);
}
}
}