'C# worker service vs windows service
What is the big difference between the worker service project template and the windows service project template and which is better to use?
When can I use a worker service & windows service?
Solution 1:[1]
Both are real services.
Windows Services have existed for over 20 years. They start most often at system startup and run permanently.
A Worker Service is also a real process, but is intended as a background service for a front-end application; it starts with the application and stops with the application.
That said, a Worker Service can also be configured to run as a Windows Service.
So from a C# perspective, a worker service is the same idea as a Task or a Thread. But it runs in its own address and memory space. Therefore, it won't crash just because the application crashes.
Solution 2:[2]
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. You can easily create services by creating an application that is installed as a service.
worker service is a .NET project built using a template which supplies a few useful features that turn a regular console application into something more powerful. A worker service runs on top of the concept of a host, which maintains the lifetime of the application. The host also makes available some familiar features, such as dependency injection, logging and configuration.
Windows Service vs. Other Visual Studio Applications
- You cannot debug or run a service application by pressing F5 or F11
- Unlike some types of projects, you must create installation components for service applications.
- The Main method for your service application must issue the Run command for the services your project contains.
- Windows Service applications run in a different window station than the interactive station of the logged-on user.
- Windows service applications run in their own security context and are started before the user logs into the Windows computer on which they are installed. You should plan carefully what user account to run the service within.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | InteXX |
Solution 2 | thisisnabi |