Created
January 22, 2013 16:59
-
-
Save Andorbal/4596273 to your computer and use it in GitHub Desktop.
Basic program shell for running a Windows service from the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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