1.计时器,应用场景,定时指定程序执行某个任务或者动作
演示代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace 计时器
{
class Program
{
/// <summary>
/// 计时器
/// </summary>
static System.Threading.Timer timer;
/// <summary>
/// 主程序入口
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Task.Factory.StartNew(Dowork);
//Dowork();
//var oc=new OptionClass();
//oc.Start();
Console.Read();
}
/// <summary>
/// 计时器定时打印
/// </summary>
public static void Dowork()
{
timer = new System.Threading.Timer(o =>
{
Print();
});
//延迟3秒启动计时器,以后每隔4秒执行一次
timer.Change(3 * 1000, 4 * 1000);
// Task a = new Task(aa);
//timer = new System.Threading.Timer(new TimerCallback(Print));
}
/// <summary>
/// 打印
/// </summary>
public static void Print()
{
Console.WriteLine("111111111111111111111");
}
}
}