Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good to have windows service or console application?

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

like image 637
Juni Avatar asked Jul 30 '12 12:07

Juni


People also ask

What is the difference between console application and Windows service?

The key difference between a process running as an app versus as a service is that the service can operate entirely outside the normal association with a user and session. Thus services can run such that they start before any user logs in and can continue running after users log off.

When should you use Windows services?

Take advantage of Windows services to build applications that you want to run in the background or execute automatically at predefined intervals of time. A Windows service is a long-running application that can be started automatically when your system is started.

Why do we need console application?

A console application is primarily designed for the following reasons: To provide a simple user interface for applications requiring little or no user interaction, such as samples for learning C# language features and command-line utility programs.

What are the benefits of Windows services?

Microsoft Windows services, formerly known as NT services, enable you to create long-running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface.


2 Answers

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?

like image 55
Dave New Avatar answered Nov 03 '22 01:11

Dave New


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...

like image 33
jeroenh Avatar answered Nov 03 '22 00:11

jeroenh