Hello All,
We have requirement that need to convert existing console application to windows service same code setup.
what is the process to create windows service and publish in the windows service.
Regards
Anand.
Hello All,
We have requirement that need to convert existing console application to windows service same code setup.
what is the process to create windows service and publish in the windows service.
Regards
Anand.
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.
Naimish MakwanaPosted Aug 14, 2024, 4:45 AM
Converting a console application to a Windows service involves a few steps. Here’s a high-level overview of the process:
Create a new Windows Service project: In your solution, select Add, and Click New Project. Select the Windows Service (.NET Framework) template1.
Add an installer for the Windows Service: This installer registers the service with the control manager. You can add an installer by right-clicking on the blank area and selecting "Add installer"2.
Update the service name, display name, and description of the service: You can do this in the
ProjectInstaller.Designer.cs=>InitializeComponent()method2.Implement the real service: Open your service class (in my case
MyWindowService.Designer.cs) and you should have two default methods -OnStart&OnStop (). Use an event logger to log the Windows Service information2.Integrate your console app code into the Windows Service structure: The most straightforward approach is to create a new Windows Service to have the right structure of your main entry point and the correct references, then integrate your console app code into that structure3.
Install the Windows Service: You can use the
installutil.exetool that comes with .NET Framework to install your Windows Service. The command would look something like this:installutil.exe YourService.exe.Refer below links:
https://www.c-sharpcorner.com/blogs/how-to-convert-existing-c-sharp-application-to-window-service
https://stackoverflow.com/questions/15493603/how-to-convert-a-console-application-to-a-windows-service
Thanks