My question is How can I write the windows service in .net core which we used to write in prior .net versions ?
Lots of links/articles explain how to host your .net core application as windows service. So this is the only way I can create windows service ?
If yes, can anyone please provide the links/example of it
Thanks !
Not sure if there is a default way of doing this. You can however let your core application inherit from ServiceBase and implement the necessary overrides. We do this in our application (note that we target the full framework, not core). The original idea for this came from the following articles:
Note that these articles still reference DNX (from the .NET Core beta days) - these days your core app will compile to an exe, so you can adjust their examples to cater for that.
This is one way of building windows services using .net core.
Example of writing windows service (taken from github project's page):
It is not perfect but IMHO it is pretty nice.
This is another simple way to build windows service in .net Core (console app)
DotNetCore.WindowsService
Simple library that allows one to host dot net core application as windows services.
Installation
Using nuget: Install-Package PeterKottas.DotNetCore.WindowsService
Usage
Create your first service, something like this:
Api for services:
Run the service without arguments and it runs like console app.