C# System.Timers.Timer的使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TimersTimer
{
class Program
{
static void Main(string[] args)
{
var timer = new System.Timers.Timer(1000);
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Start();
Thread.Sleep(10000);
timer.Stop();
timer.Dispose();
Console.Read();
}
static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("System.Timers.Timer {0:T}", e.SignalTime);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TimersTimer
{
class Program
{
static void Main(string[] args)
{
var timer = new System.Timers.Timer(1000);
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Start();
Thread.Sleep(10000);
timer.Stop();
timer.Dispose();
Console.Read();
}
static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("System.Timers.Timer {0:T}", e.SignalTime);
}
}
}