C#中倒计时汇总
一:
int time=0;
while(true){
Thread. Sleep(1000);
time=time+1;
Console.Write(time)
if(time>=180){
//这里放时间到了之后执行的操作,会被循环执行。
//不想循环请加break;
}
}
二:
Task.Factory.StartNew(() =>
{
boolTimeDown = true;
int time = 0;
while (boolTimeDown)
{
Thread.Sleep(1000);
time = time + 1;
Console.Write(time);
if (time <= 60)
{
LblGetCode.Text = "剩余" + Convert.ToString(60 - time) + "秒";
}
else
{
LblGetCode.Text = "获取验证码";
boolTimeDown = false;
break;
}
}
});