7

I have a tasks table in my db. I want to read data from this table and run tasks. Which one is better whether to have it as windows service or a console application running. The server on which this will be run will not be shutdown

Juni
  • 95
  • 1
  • 4

6 Answers6

8

You most likely want to use a windows service.

Benefits:

  • You can control the user (and the rights associated with this user account) which starts the process
  • An automatically started process means the desktop need to be on, not user logged, for the service to run
  • A policy on failure can be defined (try to restart n times run a specific program if fails)
  • A dependency can be defined (if you depend on other sevices)
  • You can wrap your script in an invisible window
  • You can easily start/stop/restart the script (net start <scriptname>)

Quoted from here: What is the benefit of developing the application as a windows service?

Community
  • 1
  • 1
Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 2
    Excellent answer. I would add that, for advances scenarios, you can host a small web application directly within your service. This will allow you to remotely control or monitor the service (just beware of the security implication). An example of this is the [Rabbitmq management service](http://www.rabbitmq.com/management.html). A small embedded web server allows the amdinistrator to monitor the service remotely – Steve B Jul 30 '12 at 13:06
4

A running console app is not an option, as the others have stated.

If you just want the task run every x minutes the simplest option is a scheduled task using a console application.

A windows service has it's benefits, but is a little bit more complex to implement and deploy. However if your app needs to be 'always on' (e.g. need to react to external triggers, listen to message queue, ...), a windows service is the only option. As the others have said, the services infrastructure also provides more management capabilities, built-in integration with the event log, restart and failover options...

jeroenh
  • 26,362
  • 10
  • 73
  • 104
  • Thanks Jeroenh!! Yes exactly thats my requirement i should be able to trigger the task say every x mins.. Can you pls tell how complex it is with services? – Juni Jul 30 '12 at 13:01
  • http://www.pedautreppe.com/post/How-to-create-(and-deploy)-a-windows-service-in-C-.aspx – jeroenh Jul 30 '12 at 13:41
  • But as I stated in my answer, if you simply need the task to run every x minutes, a scheduled task is much easier and has a lot of the same advantages (can run unattended, easy deployment, integration with event log, etc.) – jeroenh Jul 30 '12 at 13:42
0

Windows service, because it does not require logged-in user.

Sergei Rogovtcev
  • 5,804
  • 2
  • 22
  • 35
0

I would say; Windows Services.

In that case (among other things) you don't need a user to be logged in, you can configure it in a matter to restart automatically if it shuts down for some reason and you (could) have extensive rights throughout the system.

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
0

Windows service generally. Console app will need to be restarted if the server reboots while a windows service can start automatically.

Brian
  • 2,229
  • 17
  • 24
0

You should look at: https://github.com/thedavejay/Self-Installing-Windows-Service

It allows you to debug as a console application and then install it as a windows service.

mdiehl13
  • 472
  • 6
  • 19
TheDaveJay
  • 753
  • 6
  • 11