I found plenty of partial answers, but nothing really sufficient.
The case: App is a working command line app, with no user interaction, except for the ability to receive an key press on enter to stop, this is already written in a way that disables even that when not run as Environment.UserInteractive == true.
I'm using Visual Studio 2010.
The problem is I need to convert this app to a windows service. Is it "just" making a new class file as a service, and have it call my start and stop methods on the existing application?
How about the installer (VS' default msi installer), can the existing installer project be "upgraded" to handle the Service installation as well?
I messed with this before, and ended up with an installer that kept refusing to install, as it kept detecting the service as already being installed, stopping the install process by then promptly rolling back everything. The service it detected were the one it had just installed.
Keep C# application running
Check the link above. I provide some code as well as a link describing using a console for double-duty as Console and Service. I will use a console project and check for UserInteractive before running as a service. This way you can debug as if it's a console, but install it as a service on a production server.
With regards to installing, I don't have experience with installing from .msi, but we use a batch script to install the service (using sc.exe) and then its just a matter of replacing files if you update the code.
To run a console app as either a Windows Service or a Console application, write a single console application and use command line arguments to determine if you should run directly or start up the service. Include an installer/uninstaller to install as a windows service with the right command line arguments.
Here's a base class we use that provides this functionality.
Best thing for you to do is to start a new Project as a windows service. In this new project you will find Service1.cs and this is the file that will be run from start. the following code will be int the file:
It isnt that hard to figure out what to do from here. Simply add your classes to the project and make sure that you copy your main code in the the OnStart() function. Of course you might have to slightly edit the code to make sure it has no readlines in it.
Now you must create and installer. How you can do this can be found here: http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.100%29.aspx
I hope this helped :D
Kind Regards
RoXaS