日期:2014-05-18 浏览次数:21041 次
private void WS()
{
Thread t = new Thread(new ThreadStart(delegate() { TWS(); })); //开启一个线程
t.IsBackground = true; //设置为后台线程
t.Start();
}
public void TWS()
{
bool bl = true;
while (true)
{
SolidColorBrush SCB = new SolidColorBrush();
if (bl==true)
{
bl = false;
SCB.Color = Colors.Red;
}
else if (bl==false)
{
bl = true;
SCB.Color = Colors.Green;
}
this.BWCC(SCB);
Thread.Sleep(500);
}
}
//******修改颜色的委托******
delegate void BWCC_Handle(SolidColorBrush SCB);
void BWCC(SolidColorBrush SCB)
{
if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread)
{
this.Dispatcher.Invoke(new BWCC_Handle(this.BWCC), SCB);
}
else { this.Background = SCB; }
}