none
Window service with timer of one month RRS feed

  • Question

  • How we can set the timer of window service to 1 month, I am trying but it is not getting set as it take time in milliseconds.
    Tuesday, December 23, 2014 5:48 PM

Answers

  • I question the benefit of using a timer for a month. At that interval the timer might or might not ever fire (depends upon whether the service or machine is restarted). If you want something to run once a month then a service is probably not the best choice. I would consider a scheduled task that runs once a month instead. It is easier to write, debug and run.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Tuesday, December 23, 2014 6:45 PM
    Moderator

All replies

  • What type of timer are you using? System.Timers.Timer and Windows.Forms.Timer are limited to a maximum interval of Int32.MaxValue milliseconds which is a little less than a month. System.Threading.Timer allows the interval to be set with an Int64 value which is much more than a month. You could either use System.Threading.Timer, or you could split the interval in half and use one of the other timers (only do your processing on every second timer pop).

    However, you might want to think about what you mean by a month. Is it a calendar month (28 to 31 days) or 30 days. If a calendar month, what date is one month after 31 January?

    Tuesday, December 23, 2014 6:11 PM
  • I question the benefit of using a timer for a month. At that interval the timer might or might not ever fire (depends upon whether the service or machine is restarted). If you want something to run once a month then a service is probably not the best choice. I would consider a scheduled task that runs once a month instead. It is easier to write, debug and run.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Tuesday, December 23, 2014 6:45 PM
    Moderator