Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
Created April 23, 2013 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mizanRahman/5441890 to your computer and use it in GitHub Desktop.
Save mizanRahman/5441890 to your computer and use it in GitHub Desktop.
running windows service from console
using System;
using System.ServiceProcess;
public class MyService : System.ServiceProcess.ServiceBase
{
static void Main(string[] args)
{
MyService service = new MyService();
if (Environment.UserInteractive)
{
service.OnStart(args);
Console.WriteLine("Service Started. at {0}", DateTime.Now);
Console.WriteLine("Press any key to stop program");
Console.Read();
Console.WriteLine("Stopping The Service.");
service.OnStop();
}
else
{
ServiceBase.Run(service);
}
}
public MyService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down
//necessary to stop your service.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment