zoukankan      html  css  js  c++  java
  • 用timer自定义计划任务时间

    应业务需求,需要将指定程序,按照指定时间进行运行,

    而windows计划任务最小运行间隔时间为1分钟,完全不能满足当前需求,

    有两种方案,一种是安装win服务方式,考滤到维护困难,另一种是timer方式,方便易于维护,简单

    可参考以下代码片断

        private static void Main(string[] args)
            {
                //上传频率 
                int UploadFre =int.Parse(System.Configuration.ConfigurationSettings.AppSettings["UploadFre"].ToString());
                
                System.Timers.Timer newTime = new System.Timers.Timer();
                newTime.Elapsed += new ElapsedEventHandler(newTime_Elapsed);
                newTime.Interval = (UploadFre > 1 ? UploadFre : 1)*1000;//设计你的执行频率,http://eccs.taobao.com
               
                newTime.AutoReset = true;
                newTime.Enabled = true;
                
                Console.ReadLine();
            }
             
    
            static void newTime_Elapsed(object sender, ElapsedEventArgs e)
            {
                
               //调用你的实际方法http://eccs.taobao.com
               // ServiceBase.RunService(dtTime, appPath);
            }    
  • 相关阅读:
    Struts2框架
    读者写者问题
    哲学家就餐问题
    理解中断
    理解处理机调度
    理解死锁
    理解进程
    Linux CentOS 6.7 挂载U盘
    家庭-养老院模型理解IOC和DI
    Bash基础
  • 原文地址:https://www.cnblogs.com/chenhuzi/p/4917787.html
Copyright © 2011-2022 走看看