class Program
{
private static System.Timers.Timer aTimer;
static void Main(string[] args)
{
//int a, b;
//ThreadPool.GetMaxThreads(out a, out b);
//Console.WriteLine("线程池默认最大工作线程数:" + a.ToString() + " 默认最大异步 I/O 线程数:" + b.ToString());
aTimer = new System.Timers.Timer(100);
aTimer.AutoReset = true;
aTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}
{
private static System.Timers.Timer aTimer;
static void Main(string[] args)
{
//int a, b;
//ThreadPool.GetMaxThreads(out a, out b);
//Console.WriteLine("线程池默认最大工作线程数:" + a.ToString() + " 默认最大异步 I/O 线程数:" + b.ToString());
aTimer = new System.Timers.Timer(100);
aTimer.AutoReset = true;
aTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Interval = 1000;
this.timer1.Enabled = true;///是否正在运行;
this.label1.Text = DateTime.Now.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Text = DateTime.Now.ToString();
}
}
}
{
private static System.Timers.Timer aTimer; static void Main(string[] args)
{
aTimer = new System.Timers.Timer(100);
aTimer.AutoReset = true;
aTimer.Enabled = true;
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);//绑定定时器事件
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
}
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}