Skip to content

@ferventcoder /CustomService.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Debugging Windows Services
public partial class CustomService : ServiceBase
{
protected override void OnStop()
{
//normal shutdown code here
}
protected override void OnStart(string[] args)
{
//normal startup code here
}
public void RunConsole(string[] args)
{
OnStart(args);
if ((args.Length > 0) && (Array.IndexOf(args, "/console") != -1))
{
Console.WriteLine("Please press enter to continue...");
Console.ReadLine();
}
OnStop();
}
}
public class ServiceStartRedirect
{
#region Methods
private static void Main(string[] args)
{
if ((args.Length > 0) && (Array.IndexOf(args, "/console") != -1))
{
var service = new CustomService();
service.RunConsole(args);
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new CustomService()
};
ServiceBase.Run(ServicesToRun);
}
}
#endregion
}
@ferventcoder

In the properties of the project, under Debug -> Start Options -> Command Line Arguments: add

/console
@ferventcoder

Also make sure in Properties -> Application -> Output type: is set to

Console Application   

and

Startup object: is set to

ServiceStartRedirect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.