此代码在未放入线程中时起作用,为什么标签在放入线程中时不更改?做一个线程。加入也可以。但这只会减慢UI的速度。
public void Filechecker()
{
new Thread(() =>
{
if (status == 1)
{
for (int i = 0; i < 100; i++)
{
if (status == 0)
{
Labelstatus.Text = "Files okay";
Labelstatus.ForeColor = Color.Green;
break;
}
Thread.Sleep(100);
if (i == 99)
{
Labelstatus.Text = "Warning no activity 1";
Labelstatus.ForeColor = Color.Red;
}
}
}
}).Start();
}