简体   繁体   中英

How can I effectively set the system.timer to run my windows service quarterly (once in 12 weeks)?

How can I run my windows service once in 12 weeks? I implemented it using timers, and I am assigning the timer interval as (12*7*24*60*60*1000 milliseconds). Is there any issue if i use the timer for such a duration (12*7*24*60*60*1000 milliseconds).

If it causes an issue please suggest an alternate way to run my windows service once in every 12 weeks.

Well, yes it would cause issues. Int32.MaxValue is 2,147,483,647.

Can't you just schedule your service to run once in 12 weeks? You can use

net start yourservice
net stop yourservice

(as per sajoshi's comment: I meant you can start and stop your service with Task Scheduler)

You should be using the windows task scheduler for this kind of thing. You can set it to start any application (not windows service) are various intervals.

Besides, why have an application running on a server using up memory and cpu cycles whne you only need it once every 12 week!

I think the better approach will be comparing dates.

  1. Create a Windows service with timer with one hour interval.
  2. In the onstart event of the service store the current date.
  3. In the timer_tick / elapsed event, check the difference between current date and stored date, if it is 12 do operations. Also update the current date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM