why to use windows service

hi

though i have used few windows services, yet i am not able to figure out , what specific problems it solves , and where specifically i should use them.

why not to use console app and put them in windows task scheduler rather.



The simplest answer is because services are generally application/programs/processes that run regardless of whether the user is signed in or not. Another distinction is that *most* services, in general, need to run for as long as the operating system is loaded.

One example of this would be the Print Spooler:
Say that UserA needs to print and knows that UserB has a printer that is attached to his/her computer and that this printer is shared out for local network usage. Now if UserB is not logged into his her computer, then something needs to be running on the computer to allow for a print request to be processed. In this case, the Print Spooler service allows for UserA to send a print job to UserB's computer, the print spooler in turn sends the job to the target printer. This process could not be accomplished by a scheduled task that is set to run as UserB because you never know explicitly when UserA will need to print. Also, just leaving UserB logged in represents a hole in your security.

-saige-



The simplest answer is because services are generally application/programs/processes that run regardless of whether the user is signed in or not. Another distinction is that *most* services, in general, need to run for as long as the operating system is loaded.

One example of this would be the Print Spooler:
Say that UserA needs to print and knows that UserB has a printer that is attached to his/her computer and that this printer is shared out for local network usage. Now if UserB is not logged into his her computer, then something needs to be running on the computer to allow for a print request to be processed. In this case, the Print Spooler service allows for UserA to send a print job to UserB's computer, the print spooler in turn sends the job to the target printer. This process could not be accomplished by a scheduled task that is set to run as UserB because you never know explicitly when UserA will need to print. Also, just leaving UserB logged in represents a hole in your security.

-saige-



Also in the above example, other services come into play that allow for UserA to send a simple print job to UserB's computer.

-saige-



Services are applications that look over other applications (such as an anti-virus program), or are used by other applications (such as SQL Server).

They cannot be started from the Task Scheduler, because you never know beforehand when they will be required.

At first sight, there are services that could be defined in a dll that runs only while an application uses it. Think of databases for instance. The Access database engine does not run continually on the computer, it is launched by the application that needs to Access the database, and then "dies" when the application stops.

You might Wonder why SQL Server runs as a service instead of doing the same thing that Access does. There are many reasons for that.

The main one is that it can be called from other computers. In order to do so, it needs to be ready to answer anytime.

On an individual station (SQL Server Express), because of all it does, SQL Server takes longer to start. It would slow down the first access to it from an application if an application needed to start it before using it.

Another one, more important that one, is that SQL Server still do work in the background even when applications do not use it. If it was to stop every time an application stops, it would not be able to do these background tasks efficiently.



bit different solution, i can use task scheduler to start an application every minute, which is same as windows service,



But that is because Task Scheduler, itself, is a windows Service.

-saige-

Share this

Related Posts

There was an error in this gadget