未完善 后续再修改
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 ///7 /// 设置定时器 8 /// 9 /// 控制开始和暂停10 ///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 else27 {28 aTimer.Enabled = false; //停止引发Elapsed事件,且取消线程池中当前等待队列中剩余任务的执行29 aTimer.AutoReset = false;30 aTimer.Stop();31 aTimer.Close();32 33 }34 35 }36 37 /// 38 /// 定时被调用39 /// 40 ///41 private void GenerateOnce_BranchParamEstimationTable(object source, System.Timers.ElapsedEventArgs e)42 {43 //48 }