C# System.Threading.Timer的使用

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);
        }
    }
}


posted @ 2018-04-11 15:14  dxm809  阅读(199)  评论(0编辑  收藏  举报