Search code examples
c#.net.net-corewindows-servicesbackgroundworker

How to use Native Windows Service Base Class functionality into .Net Core 5.0 Windows Service using BackgroundService?


I’m creating a windows worker service in Visual Studio 2022 with new guidelines from Microsoft to create windows services using .Net Core 5.0 Windows Service using BackgroundService.

I want to use some functions like:

protected override void OnCustomCommand()
protected override void OnShutdown()

which are natively available in Windows Services built using .Net Framework but not in .Net Core Background services.

Is it possible to include this functionality in the new .Net Core 5.0 Windows services?


Solution

  • Finally found a way to do this Instead of creating Windows services from Background worker services try creating them from a console application then importing the base class into your Service class. This way you will be able to import and use all the functionality of windows services in your .Net Core 5.0 and above projects.

    Here is the link on How to create Windows Service in Net Core.