经典案例, 每隔一分钟执行一次的定时任务, 用 thread+ while(true) 还是timer


经典案例, 每隔一分钟执行一次的定时任务, 用 thread+ while(true) 还是timer

 

1.

while ( true )
{
//dosomething
System.Threading.Thread.Sleep(60 * 1000);
}


2.
一种是的等待一分钟,一种是到了一分钟之后触发执行某个事情。

1
2
3
4
5
6
7
8
9
10
11
12
13
private  static  System.Timers.Timer timers =  new  System.Timers.Timer(60 * 1000);
         static  QueueIndex()
         {
             timers.AutoReset =  true ;
             timers.Enabled =  true ;
             timers.Elapsed +=  new  System.Timers.ElapsedEventHandler(Timer_Call);
             timers.Start();
         }
 
private  static  void  Timer_Call( object  sender, System.Timers.ElapsedEventArgs e)
   {
//dosomething
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM