System.Threading.Thread.Sleep()
一个简单的程序,就是用AJAX Extensions中UpdatePenel控件中加入一个名为txtTime的Label来显示时间,利用Timer1的Tick事件来触发数据的跟新。我想请问一下,以下的程序中System.Threading.Thread.Sleep(100);这句对本程序起什么作用?因为我注释掉这句后,运行起来会不一样,我感觉好像对随机数有影响,是这样的么?请大虾帮忙解答,谢谢。protected void Timer1_Tick(object sender, EventArgs e)
{
txtTime.Text = "服务器现在的时间是:" + DateTime.Now.ToLongTimeString();
int red = new Random().Next(255);
System.Threading.Thread.Sleep(100);//暂停100毫秒
int green = new Random().Next(255);
System.Threading.Thread.Sleep(100);
int blue = new Random().Next(255);
System.Threading.Thread.Sleep(100);
int alph = new Random().Next(100);
txtTime.BackColor = Color.FromArgb(alph, red, green, blue);
txtTime.ForeColor = Color.FromArgb(green, blue, red);
}