C# System.Threading.Timer的使用

时间:2022-11-09 09:01:29

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ThreadTimerExam
{
    class Program
    {
        static void Main(string[] args)
        {
            var timer = new System.Threading.Timer(TimerAction, null, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3));
            Thread.Sleep(15000);
            timer.Dispose();
            Console.Read();
        }
        static void TimerAction(object obj)
        {
            Console.WriteLine("System.Threading.Timer {0:T}", DateTime.Now);
        }
    }
}

C# System.Threading.Timer的使用