我有一项服务,目前我认为它每 10 分钟运行一次,但我希望它每天晚上 7 点运行,我需要更改什么?……
private Timer _timer;
private DateTime _lastRun = DateTime.Now;
protected override void OnStart(string[] args)
{
_timer = new Timer(10 * 60 * 1000); // every 10 minutes??
_timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (_lastRun.Date < DateTime.Now.Date)
{
// stop the timer
_timer.Stop();
try
{
SmartImportService.WebService.WebServiceSoapClient test = new WebService.WebServiceSoapClient();
test.Import();
}
catch (Exception ex) { }
_lastRun = DateTime.Now;
_timer.Start();
}
}