我正在使用以下计时器在 .Net Core IHosted Service 中运行:
TimeSpan ScheduledTimespan;
string[] formats = { @"hh\:mm\:ss", "hh\\:mm" };
string strTime = Startup.Configuration["AppSettings:JobStartTime"].ToString();
var success = TimeSpan.TryParseExact(strTime, formats, CultureInfo.InvariantCulture, out ScheduledTimespan);
Timer _timer = new Timer(JobToRun, null, TimeSpan.Zero, ScheduledTimespan);
我正在使用这个特定的重载函数,
public Timer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period);
但是JobToRun
会在控制到达它的时候立即执行。
我该如何使其每天在特定时间运行?
提前感谢。