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;
                                }
                            }
                        });

posted on 2018-03-08 22:01  连一粝  阅读(3097)  评论(0编辑  收藏  举报

导航