DateTime target = DateTime.Today.AddHours(20);
if (target < DateTime.Now) {
target = target.AddDays(1);
}
System.Threading.Thread.Sleep(target - DateTime.Now);
用windows service吧,
public partial class Service1 : ServiceBase
{
private Timer timer;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
DateTime nowTime=DateTime.Now;
DateTime startTime=new DateTime(nowTime.Year,nowTime.Month,nowTime.Day+1,8,0,0);
timer = new Timer(delegate(object param)
{
//执行]执行方法
}, null, startTime.Subtract(DateTime.Now).Milliseconds, 24 * 60 * 60 * 1000);
}
protected override void OnStop()
{
timer.Dispose();
}
}