Skip to main content

Posts

Showing posts from April, 2020

Building Cross-Platform Worker Services with .NET Core

If you have been in software development long enough, at some point you must have come across a need to have a long running background service. This came in the form of either windows services or daemons (for non windows systems). With the release of .NET Core 3.0, there is a new type of application template which was introduced to address the need of building cross-platform worker services. This could either be a Windows service or a systemd process that runs on Linux . You can either create the worker service using the Visual studio template as below Or use the command line and run command dotnet new worker The created project has the below file structure Program.cs   is the entry point for the application that registers and builds the host.  Worker.cs   file contains default worker. It inherits from   Microsoft.Extensions.Hosting.BackgroundService  class and overrides the  ExecuteAsync  method. Below is the Worker.cs code The code in  ExecuteAsync