C# 定時器事件(設置時間間隔,間歇性執行某一函數,控制台程序)


定時器事件代碼 
static void Main(string[] args)
{
         Method();
         #region 定時器事件 
         Timer aTimer = new Timer();
         aTimer.Elapsed += new ElapsedEventHandler(TimedEvent);
         aTimer.Interval = seconds * 1000;    //配置文件中配置的秒數
         aTimer.Enabled = true;
         #endregion
         string strLine;
         do
         {
              strLine = Console.ReadLine();
         } while (strLine != null && strLine != "exit");

}  
private static void TimedEvent(object source, ElapsedEventArgs e)
{
    Method();
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM