0

I'm setting up a timer for my windows services with a following settings: The timer will start after 10 days, and has a multiplier of 3 i.e. It'll run again after 10*3 = 30 days, and then 30*3 = 90. This timer should stop after 180 days. I'm trying to achieve this in such a way that we calculate the time closest in the future, and just chill out until that time comes, fire the requests you need to fire and then figure out the next closest time again.

So far I've only tried setting up the timer as follows. but lost on the multiplier part.

private readonly Timer _timer

_timer.Interval = TimeSpan.FromDays(10).TotalMilliseconds;

 _timer.Elapsed += DoWork;

_timer.Start();

// Setup timer to do work

private void DoWork(){}
babu ji
  • 1
  • 2
  • See [this question and its comments](https://stackoverflow.com/questions/1624789/maximum-timer-interval) – Sam Axe Oct 15 '19 at 19:05
  • 1
    Setting `Timer.Interval` to 10 days is a very poor design choice. What if the Windows Service (or the server) restarts? Instead, you should store `DateTime` value somewhere and periodically compare its value against the current date/time. – 41686d6564 stands w. Palestine Oct 15 '19 at 19:07
  • Have you looked into [Hangfire](https://www.hangfire.io/)? – mason Oct 15 '19 at 19:16
  • 4
    Not sure what your project is but this sounds like something that Task Scheduler would be good for since you just want it to "chill" for x amount of days. – Sorceri Oct 15 '19 at 19:24
  • What you're trying to do is unusual. Can you tell us the real problem you're trying to solve? – Jim Mischel Oct 15 '19 at 23:41

0 Answers0