zoukankan      html  css  js  c++  java
  • C# 定时器计划任务

    函数类:

    public class MyPlan
    {
    public void RunMyplan(object source, ElapsedEventArgs e)
    {
    //读取配置文件设定的日期时间
    string SetData = ConfigurationManager.AppSettings["DateNum"].ToString();

    //获取现在的系统时间
    DateTime nowDate = DateTime.Now;
    string d = nowDate.Day.ToString();

    //比较是否符合设定的时间,SetDate中是否有d的存在
    int i = SetData.IndexOf(d);
    if (i >= 0)
    {
    //计划任务要执行程序
    Console.Write(" Today is " + d + " day!");
    }
    }
    }

    主程序类:

    MyPlan myplan = new MyPlan();

    Timer t = new Timer(2000);
    t.Elapsed += new ElapsedEventHandler(myplan.RunMyplan);

    t.Start();

    Console.WriteLine("即将开始读取数据:");
    Console.ReadLine();

    配置文件:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <!--设定每月执行计划任务的日期,先设定每月的16号,17号,25号执行-->
    <add key="DateNum" value="8,17,25"/>
    </appSettings>
    </configuration>

  • 相关阅读:
    自制凉皮
    牛人
    史记
    阅读detection
    最近的购书清单
    不要轻易挑战用户的习惯,否则会被用户打脸!
    INVEST原则的应用
    谈谈Backlog梳理活动
    要写封闭式的用户故事
    敏捷教练的八种失败角色
  • 原文地址:https://www.cnblogs.com/wlming/p/5113318.html
Copyright © 2011-2022 走看看