time的用法


线程计时器(System.Threading.Timer)
System.Windows.Threading.DispatcherTimer tRecorderTimer;
if (tRecorderTimer == null) { tRecorderTimer = new DispatcherTimer(); tRecorderTimer.Interval = TimeSpan.FromSeconds(1); tRecorderTimer.Tick += updateListBox_Tick; } tRecorderTimer.Start();

 

服务中的time

基于服务器的计时器(System.Timers.Timer)

System.Timers.Timer不依赖窗体,是从线程池唤醒线程,是传统的计时器为了在服务器环境上运行而优化后的更新版本。

 System.Timers.Timer aTimer = new System.Timers.Timer();
           aTimer.Elapsed += new System.Timers.ElapsedEventHandler(Start);
           aTimer.Interval = GetSlientUpdateTime();
           aTimer.Enabled = true;

 

posted @ 2016-11-04 09:49  莫欺  阅读(368)  评论(0编辑  收藏  举报