Created
April 23, 2013 08:48
-
-
Save mizanRahman/5441890 to your computer and use it in GitHub Desktop.
running windows service from 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; | |
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