• 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;
            }
        }
    }
  • 相关阅读:
    【Java】关于Spring框架的总结 (三)
    【Java】关于Spring框架的总结 (二)
    【Java】关于Spring框架的总结 (一)
    关于各编程语言冒泡排序的实现
    【Java】关于MyBatis框架的总结
    Linux 查看服务器开放的端口号
    网络安全随笔
    Window随笔
    Linux随笔
    Powercli随笔
  • 原文地址:https://www.cnblogs.com/jshchg/p/12950853.html
Copyright © 2020-2023  润新知