いくつかの時間指定機能で実行されている Windows サービスがあります。
_timer = new Timer(1 * 60 * 1000); // every 1 minute
_timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
_timer.Start();
_fbtimer = new System.Timers.Timer(48 * 60 * 60 * 1000);
_fbtimer.Elapsed += new System.Timers.ElapsedEventHandler(fbtimer_Elapsed);
_fbtimer.Start();
//Weekley Snapshot
_ventimer = new System.Timers.Timer(2 * 60 * 1000);
_ventimer.Elapsed += new System.Timers.ElapsedEventHandler(ventimer_Elapsed);
_ventimer.Start();
//Weekly Activity
_tevtimer = new System.Timers.Timer(2 * 60 * 1000);
_tevtimer.Elapsed += new System.Timers.ElapsedEventHandler(tevtimer_Elapsed);
_tevtimer.Start();
How do i set the timer to occur say once a week, or even better set it to a specific time on one day a week, without using quatrz/windows scheduler or a too different method.
Addition: this is how i am running a task everyday at 10
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//log.Info("Info - Check time");
DateTime startAt = DateTime.Today.AddHours(10);
if (_lastRun < startAt && DateTime.Now >= startAt)
{
_timer.Stop();
//Stuff
_lastRun = DateTime.Now;
_timer.Start();
}
}