zoukankan      html  css  js  c++  java
  • System.Timers.Timer

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Threading;
    
    namespace Test
    {
        public partial class Form1 : Form
        {
            System.Timers.Timer timerTest1 = new System.Timers.Timer();
    
            private static void timefunc(object state)
            {
                Trace.WriteLine(string.Format("into Timer1_Elapsed,{0}", DateTime.Now.ToString()));
                System.Threading.Thread.Sleep(3000);
    
                Trace.WriteLine(string.Format("exit Timer1_Elapsed,{0}", DateTime.Now.ToString()));
            }
    
            public Form1()
            {
                InitializeComponent();
    
                timerTest1.Interval = 1;  // 立即执行
                timerTest1.Elapsed += Timer1_Elapsed;
                timerTest1.AutoReset = true;
            }
    
            private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                timerTest1.Interval = 2000000;  // 设置比较大的值,以便重新计时
                Trace.WriteLine(string.Format("into Timer1_Elapsed,{0}", DateTime.Now.ToString()));
                System.Threading.Thread.Sleep(10000);
                Trace.WriteLine(string.Format("exit Timer1_Elapsed,{0}", DateTime.Now.ToString()));
                timerTest1.Interval = 1000;    // 重新计时开始
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                timerTest1.Enabled = true;
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                timer1.Enabled = false;
            }
        }
    }
  • 相关阅读:
    echarts 图表tooltip数据默认是按照series中的数据位置排序。 鼠标移入排序
    三位加,号
    保留整数的方法
    水印vue
    vue 省市区
    平行四边形css
    css 文字样式
    js练习题
    axios 之cancelToken原理以及使用 取消上一次请求
    身份证获取生日性别
  • 原文地址:https://www.cnblogs.com/jshchg/p/12950853.html
Copyright © 2011-2022 走看看