Worker Services in .NET Core 3.0 - The New Way to Create Services
Why Stack Overflow recommends it
Stack Overflow users link it as the go-to walkthrough for turning a .NET Core app into a Windows service using the Worker Service template.
Recommended by 2 people across 2 different months, 2020 to 2021.
What it is
A 47-minute hands-on tutorial by Tim Corey on the .NET Core 3.0 Worker Service template. It builds a demo service that calls an HTTP endpoint, adds Serilog logging, configures it to run as a Windows Service, and deploys, installs and uninstalls it with PowerShell.
What people said
Strong rec StackOverthrow · 2020-10 · Stack Overflow · on “Running .NET Core console app as a service, or redo?”
Sounds like we're working in very similar environments. We started off using console apps for our ERP integrations. Their main drawbacks are that they run on a user's desktop, so you have to RDP in as that user to manage them, and they don't restart automatically if the server reboots. I've been converting them all to Windows services. .NET Core makes it fairly easy. Tim Corey has an excellent video about how to write Windows services in .NET Core 3 [this video] . He talks about deleting and recreating the service when deploying a new version, but I haven't found that to be necessary. Just RDP in, stop the service so none of the files are in use, deploy, and start it again. It's not as simple as
Recommends Trickster91 · 2021-02 · Stack Overflow · on “What are different ways to host c# code and trigger the hosted code?”
I would suggest WorkerServices for returning tasks. The starting of the project is a bit annoying but overall it works quite nice. I watched Tim Coreys Tutorial [this video] on how to get into them.
Cites Matt · 2020-11 · Stack Overflow · on “Why are my BackgroundService Args always null?”
I am using a BackgroundService in .Net Core 3.1. There are two Sections of code, The first is the BackgroundService itself which I am using in its published format. Using the same methods from the following guide: [this video] The Second Project is a Service Controller which I am trying to use to Start the Service and pass arguments to it. The Main BackgroundService Application: public class Program { public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.File(@"C:\temp\workerservice\logfile.txt") .CreateLogger(); Log.Information($"Test Args Given {args}"); v
Cites Matt · 2020-11 · Stack Overflow · on “Is it possible to pass parameters to a BackgroundService?”
I've been trying to pass parameters to a BackgroundService as a Windows Service. Ideally I would like to use a ServiceController to do this when starting the service. This seems impossible as the Service only accepts Arguments during the Main(string[] args) which is called when the service begins when the computer turns on rather than when the ExecuteAsync is called when the service is Started. The setup I am using is from this tutorial [this video] The current solution I have implemented uses a configuration file which the Service reads when its starts, this allows for some dynamic configuration but is not ideal. Any Advice is appreciated!