12

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?

Maniero
  • 10,806
Pavan G R
  • 415
  • 3
    I think this question is better suited for SO – Naveen Sep 22 '10 at 05:03
  • 1
    Really, that's a good software design question and you'll likely have at least five good answers in five hours once you ask it on SO. – sharptooth Sep 22 '10 at 05:47
  • 1
    I voted to close, this actually belongs on SO – Jaco Pretorius Sep 22 '10 at 06:19
  • 2
    This question elicits a subjective and/or extended discussion on the merits of either. It's very much on topic here and subjective and argumentative there. –  Sep 22 '10 at 08:23
  • @Mark - depending on what the utility actually does there is a reasonably objective answer. In this case I think it's to run a scheduled task. – ChrisF Sep 22 '10 at 11:13
  • on Windows 7 you have some super cool additions to both which will affect your decision process. Ask on SO and tag with Windows-7 and I'll elaborate. – Kate Gregory Sep 22 '10 at 11:45
  • @ChrisF: "depending" does it a subjective question :-) – Maniero Sep 22 '10 at 12:07
  • @bigown - what the utility does is not subjective, merely (from this post) unknown. – ChrisF Sep 22 '10 at 12:57
  • Hmm I voted to close as better suited for SO, then I read Mark's comment and now I'm stuck! – Wizard79 Sep 22 '10 at 14:21
  • 3
    I'm not sure, I think the last sentence "Which one do you prefer and why?" would trigger the close-bots over there. Its better here since actual answers can be got here – TheLQ Sep 22 '10 at 22:23
  • 1
    Has anyone bothered to look at this question on SO - i have and there are many answers supporting both sides. – Ahmad Sep 23 '10 at 05:41
  • 1
    Well, I have expressed my detailed understanding here: http://pavangayakwad.blogspot.com/2010/09/windows-service-or-windows-task.html – Pavan G R Sep 26 '10 at 04:20

5 Answers5

5

Services are either used for administrative purposes or to offer a service to multiple applications.

Schedules are used for running a task multiple times which don't necessarily require extra permissions.

3

I've heard the arguments for using Windows Scheduler but have always opted for writting my app as a service. At first I thought it would be a better solution in a clustered environment but that's not really true. The bottom line is I didn't have a good reason other than it "felt" like better design.

Walter
  • 16,146
3

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.

Ahmad
  • 355
0

why don't you try Quartz.net
i used it once and i can say it's a powerful framework to create you own scheduler, and it provide a pre builded Service that will run your scheduled Job's (stored in database or just in a XML file) http://quartznet.sourceforge.net/

aleo
  • 139
0

If you want the user to have more control without you having to build it, use the Task Scheduler. Looks like Google does this with their apps update. Depending on the user, it's not difficult manage the task. Take the user out of the loop and create a service. Most people will never touch them.

JeffO
  • 36,816