zoukankan      html  css  js  c++  java
  • 定时执行

    using System;
    using System.Timers;
    namespace 定时器ConsoleApplication1
    {
    class Class1
    { 
      [STAThread] 
      
    static void Main(string[] args)
      
    {
       System.Timers.Timer aTimer 
    = new System.Timers.Timer(); 
       aTimer.Elapsed 
    += new ElapsedEventHandler(TimeEvent); 
       
    // 设置引发时间的时间间隔 此处设置为1秒(1000毫秒)
       aTimer.Interval = 1000
       aTimer.Enabled 
    = true
       Console.WriteLine(
    "按回车键结束程序");
       Console.WriteLine(
    " 等待程序的执行......");
       Console.ReadLine();
      }

      
    // 当时间发生的时候需要进行的逻辑处理等
    //    在这里仅仅是一种方式,可以实现这样的方式很多.
    private static void TimeEvent(object source, ElapsedEventArgs e) 
      
    {  
       
    // 得到 hour minute second  如果等于某个值就开始执行某个程序。
       int intHour   = e.SignalTime.Hour;
       
    int intMinute = e.SignalTime.Minute;
       
    int intSecond = e.SignalTime.Second;
       
    // 定制时间; 比如 在10:30 :00 的时候执行某个函数
       int iHour   = 10;
       
    int iMinute = 30;
       
    int iSecond = 00;
       
    // 设置  每秒钟的开始执行一次
       if( intSecond == iSecond )
       
    {
        Console.WriteLine(
    "每秒钟的开始执行一次!");
       }

       
    // 设置 每个小时的30分钟开始执行
       if( intMinute == iMinute && intSecond == iSecond )
       
    {
        Console.WriteLine(
    "每个小时的30分钟开始执行一次!");
       }

       
      
    // 设置 每天的10:30:00开始执行程序
       if( intHour == iHour && intMinute == iMinute  && intSecond == iSecond )
       
    {
        Console.WriteLine(
    "在每天10点30分开始执行!");
       }

      }
     
    }

    }
     

  • 相关阅读:
    java swing学习
    JCheckBox相关知识点
    【python 第五日】 函数闭包与装饰器
    【python第四日】 文件处理 生成器 迭代器
    【Python3 第三日】%和format格式化输出 函数
    【python第二日】运算符 数据类型(数字 字符串 列表 元组 字典 集合) 重新定义比较大小
    怎么设置博客园样式
    【python】第一日 python2和python3区别 命名方式 三种结构
    mybatis-generator.xml
    SpringBoot集成mybatis和mybatis generator
  • 原文地址:https://www.cnblogs.com/wangchuang/p/2473008.html
Copyright © 2011-2022 走看看