At first glance, you are creating a new form
Form1 foo = new Form1();
inside ThreadTest and never displaying the form, I assume that you intend to change the color of the form in the form using btnStart? You have two options: either pass the form to the ParameterizedThreadStart parameter, or rewrite the code to just work with the existing form.
, , , Invoke , . , - .
Edit
... , ...
private void btnStart_Click(object sender, EventArgs e)
{
ThreadTest cColor = new ThreadTest();
Thread tColor = new Thread(new ParameterizedThreadStart(cColor.ChangeColor));
tColor.Start(this);
}
public class ThreadTest
{
public void ChangeColor(Object state)
{
Form1 foo = (Form1) state;
while (true)
{
foo.theLabel = Color.Aqua;
foo.theLabel = Color.Black;
foo.theLabel = Color.DarkKhaki;
foo.theLabel = Color.Green;
}
}
}
, , , , .
tColor.IsBackground = true;
, , ... , .
private void btnStart_Click(object sender, EventArgs e)
{
CreateBackgroundColorSetter(Color.Aqua);
CreateBackgroundColorSetter(Color.Black);
CreateBackgroundColorSetter(Color.DarkKhaki);
CreateBackgroundColorSetter(Color.Green);
}
private void CreateBackgroundColorSetter(Color color)
{
var thread = new Thread(() =>
{
while (true)
{
theLabel = color;
Thread.Sleep(100);
}
});
thread.IsBackground = true;
thread.Start();
}