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  }
  • 相关阅读:
    C
    B
    A
    G
    BZOJ_1208_&_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
    Codevs_1230_元素查找_(set/Hash)
    POJ_2503_Babelfish_(Trie/map)
    POJ_2001_Shortest_Prefixes_(Trie)
    BZOJ_3670_[NOI2014]_动物园_(kmp)
    BZOJ_3196_二逼平衡树_(树套树,线段树+Treap)
  • 原文地址:https://www.cnblogs.com/panpan-v1/p/4450856.html
Copyright © 2011-2022 走看看