i need the window service for .net core that can be use to run and API
Loading
i need the window service for .net core that can be use to run and API
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Praveen MishraPosted Jul 13, 2023, 8:49 AM
Hi Isiaka ,
Please follow these steps to create window service to run API.
In this code, we have the
Programclass that serves as the entry point for our application. It checks whether the application is running in console mode or as a Windows Service. If it's running in console mode (e.g., during debugging), it starts the API using theCreateHostBuildermethod and runs it. If it's running as a Windows Service, it sets the content root directory and creates a host usingCreateHostBuilder, then callsRunAsService()to run the API as a Windows Service.The
MyApiServiceclass implements theIHostedServiceinterface, which allows the service to be started and stopped by the host. In theStartAsyncmethod, we start the web host, and in theStopAsyncmethod, we stop it.Mayooran NavamanyPosted Jul 12, 2023, 9:54 AM
Hi Isiaka
Go through the article
https://code-maze.com/aspnetcore-running-applications-as-windows-service/