开发者

scheduled task or windows service

开发者 https://www.devze.com 2022-12-30 02:31 出处:网络
I have to create an app that will read in some info from a db, process the data, write changes back to the db, and then send an email with these changes to some users or groups. I will be writing this

I have to create an app that will read in some info from a db, process the data, write changes back to the db, and then send an email with these changes to some users or groups. I will be writing this in c#, and this process must be run once a week at a particular time. This will be running on a Windows 2008 Server.

In the past, I would always go the route of creating a windows service with a timer and setting the time/day for it to be run in the app.config file so that it can be changed and only have to be restarted to开发者_运维百科 catch the update.

Recently, though, I have seen blog posts and such that recommend writing a console application and then using a scheduled task to execute it.

I have read many posts talking to this very issue, but have not seen a definitive answer about which process is better.

What do any of you think?

Thanks for any thoughts.


If it is a one per week application, why waste the resources for it to be running in the background for the rest of the week.

A console application seems much more appropriate.

The typical rule of thumb that I use is something along these lines. First I ask a few questions.

  1. Frequency of Execution
  2. Frequency of changes to #1
  3. Triggering Mechanism

Basically from here if the frequency of execution is daily or less frequent I'll almost always lean towards a scheduled task. Then looking at the frequency for changes, if there is a high demand for schedule changes, I'll also try to lean towards scheduled tasks, to allow no-coding changes for schedule changes. lastly if there is ever a thought of a trigger other than time, then I'll lean towards windows services to help "future proof" an application. Say for example the requirement changes to be run every time a user drops a file in X folder.


The basic rule I follow is: if you need to be running continuously because events of interest can happen at any time, use a service (or daemon in UNIX).

If you just want to periodically do something, use a scheduled task (or cron).

The clincher here is your phrase "must be run once a week at a particular time" - go for a scheduled task.


If you have only one application and you need it to run once a week may be scheduler will be good as there is no need to have separate service and process running on the system which will be idle most of the time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号