Skip to content

Instantly share code, notes, and snippets.

@Andorbal
Created January 22, 2013 16:59
Show Gist options
  • Save Andorbal/4596273 to your computer and use it in GitHub Desktop.
Save Andorbal/4596273 to your computer and use it in GitHub Desktop.
Basic program shell for running a Windows service from the console.
using System;
using System.ServiceProcess;
namespace ServiceTest
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
if (Environment.UserInteractive)
{
Console.WriteLine("Hit enter to exit");
var service = new Service1();
service.Start();
Console.ReadLine();
service.Stop();
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment