我想写一个每天早上7点钟工作的Windows服务。但是打击代码只工作了两天。我找不到原因。
TIA!
logger.Info("OnStart started");
System.Threading.TimerCallback callback = new System.Threading.TimerCallback(change_wpa);
var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 0, 0);
var dt2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0);
var dt3 = new TimeSpan(24, 0, 0);
if (DateTime.Now < dt)
{
logger.Info("DateTime.Now < dt");
var timer = new System.Threading.Timer(callback, null, dt - DateTime.Now, TimeSpan.FromHours(24));
}
else
{
logger.Info("DateTime.Now > dt");
var timer = new System.Threading.Timer(callback, null, dt3 - (DateTime.Now - dt), TimeSpan.FromHours(24));
}