Topshelf vs sc.exe vs Windows Service project type
Asked Answered
C

2

12

As in title I would like to ask what is difference between using these possibilities of hosting my code on Windows Service. As far as I can see, all three allow me to create exe which will be installed as a service.

Churchy answered 2/12, 2012 at 17:43 Comment(0)
P
17

Topshelf is my preference because it allows you to get the best of both worlds a service and a console application. Using sc.exe allows you to execute any console application as a service, but the exe doesn't interact as a service itself. Developing a Windows Services directly let's you have a service and interact as one with Windows, but it isn't easy to debug or run as a normal console application. Topshelf allows you to ge the best of both running as a Service and running as a normal console application.

Picard answered 2/12, 2012 at 17:48 Comment(0)
K
7

Windows Services are special application types that respond to service control messages like Start, Stop, Pause, Continue etc.

While it is true that you can use something like sc.exe to turn any kind of process into a service, those processes will not handle the previously mentioned control messages. What you will commonly find is you'll be able to start a process but not stop it etc.

What I tend to do is abstract my services out (I think Topshelf does this), have a service library that can be loaded by a native Windows Service application or a console application so that I can have the best of both worlds (usually debugging under console).

Kolomna answered 2/12, 2012 at 17:48 Comment(1)
That's what I do. Write my service as a library then I have two projects: console application and a windows service. While developing I can directly launch the service as a console application and when it's ready for release the service application is what gets deployed. Topshelf is a bit cleaner in my understanding.Charlena

© 2022 - 2024 — McMap. All rights reserved.