The following is an example of how to make a windows service a hybrid console app while also having the ability to be installed as a windows service.

program.cs

class Program
{
static void Main()
{
var program = new YOUR_PROGRAM();
if (Environment.UserInteractive)
{
program.Start();
}
else
{
ServiceBase.Run(new ServiceBase[]
{
program
});
}
}
}

YOUR_PROGRAM.cs

[RunInstallerAttribute(true)]
public class YOUR_PROGRAM : ServiceBase
{
public YOUR_PROGRAM()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Start();
}
protected override void OnStop()
{
//Stop Logic Here
}
public void Start()
{
//Start Logic here
}
}

For those unfamiliar on how to install a windows service without using an installer utility. Run the following command as an administratorC:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe -i "c:\...\YOUR_PROGRAM.exe"

Stack Overflow Answer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store