Windows Service or Windows Task Scheduler

net

I am planning to create a utility, which will query the database and store some information (on another table in the database). Its a multi-threaded utility and require to run for every 5 or 10 minutes/later may be thrice in a day.

I see two options to achieve this in C#/DotNet programming.

  • creating windows service having timer approach inside it.
  • a console program and schedule it using windows task scheduler.

Which one do you prefer and why?

Best Answer

Comments from a colleague of mine from yesterday regarding this very same topic

"there is always going to be a varied opinion on this one... My rule of thumb would be if you need something that runs every five minutes (and you dont care what time it runs or how long a run takes) or something that responds to events, use a service. If you need something to run at a particular time each day and you are sure that there will not be an over lap, use the Scheduler provided with the OS. If you need a hybrid, either use both solutions for the varying cases or find something off the shelf. (Possibly Quartz .Net) "

Jon Galloway's article from 2005 "//TODONT: Use a Windows Service just to run a scheduled process" is a good read. I suggest that the comments also be read because the discussion still continues till today and provide some good counter-arguments as well.

Personally, I agree with my colleague on this one. Keep it simple for as long as possible. And if you are deploying to Win2008 server, check out the Task scheduler and all the features the standard scheduler offers. For me, the killer was to start a scheduled task when an event occurs.