C# Timer使用方法示例
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                C# Timer使用方法示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                實例化一個timer:
// 每5分鐘執行一次,每次執行的間隔毫秒時長
System.Timers.Timer timer = new System.Timers.Timer(5*60*1000);
  ?為timer設置事件和任務循環回調方法:
 //到達時間的時候執行事件timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerTask);//設置是執行一次(false)還是一直執行(true)timer.AutoReset = true;//是否執行System.Timers.Timer.Elapsed事件timer.Enabled = true; 
  ?回調任務方法:
public void TimerTask(object source, System.Timers.ElapsedEventArgs e){lock(this){Console.WriteLine("Execute timer task ....start....");// 有動態就刪除動態,沒有則據此關閉相應的播放線程if (listView.Items.Count > 0){RemoveData();// 移除掉事件記錄}else{ucVideo.StopAll();// 關閉所有實時視頻timer.Enabled = false;// 關閉timer}Console.WriteLine("Execute timer task ....completed!");}}
  ?
轉載于:https://www.cnblogs.com/boonya/p/8693678.html
總結
以上是生活随笔為你收集整理的C# Timer使用方法示例的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 滑动加载商品列表
 - 下一篇: 元气骑士怎么换宠物?