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