zoukankan      html  css  js  c++  java
  • C#实现定时器

    未完善 后续再修改

     1 private static System.Timers.Timer aTimer = new System.Timers.Timer(); 
     3 private static int syncPoint = 0;
     4 private Int32 timeInterval_genarate = 5000; //ms 
     5  
     6  /// <summary>
     7  /// 设置定时器
     8  /// </summary>
     9  /// <param name="flag">控制开始和暂停</param>
    10  /// <returns></returns>
    11  public void Generate_BranchParamEstimationTable(bool flag)
    12  {
    13     if (flag)
    14     {
    15         if (syncPoint == 0)
    16         {
    17             aTimer.Elapsed += new System.Timers.ElapsedEventHandler(GenerateOnce_BranchParamEstimationTable); //执行的事件
    18             aTimer.Interval = timeInterval_genarate;  //设置间隔时间
    19             syncPoint = 1;
    20         }
    21         aTimer.Enabled = true; //是否触发Elapsed事件
    22         aTimer.AutoReset = true;//true为自动周期执行,false为只执行一次
    23         aTimer.Start(); //启动该Timer,start()内部还是Enable置为true来启动         25       }
    26       else
    27       {
    28          aTimer.Enabled = false; //停止引发Elapsed事件,且取消线程池中当前等待队列中剩余任务的执行
    29          aTimer.AutoReset = false;
    30          aTimer.Stop();
    31          aTimer.Close();
    32                33       }
    34 
    35  }
    36 
    37  /// <summary>
    38  /// 定时被调用
    39  /// </summary>
    40  /// <returns></returns>
    41  private void GenerateOnce_BranchParamEstimationTable(object source, System.Timers.ElapsedEventArgs e)
    42  {
    43    //
    48  }
  • 相关阅读:
    第8章 字符串
    第7章 方法
    第6章 类和对象
    第5章 数组
    第4章 循环结构、break与continue
    第3章 选择结构
    第2章 变量、数据类型和运算符
    Codeforces Round #426 (Div. 2)
    CCNA学前基础一
    Tinkoff Challenge
  • 原文地址:https://www.cnblogs.com/panpan-v1/p/4450856.html
Copyright © 2011-2022 走看看