Rewrite the main method of the Windows service like this, and it will be a console application if you run with the -c option, and yes, remember to change the project type for the console from the project properties window.
public static void Main(string[] args)
{
Service service = new Service();
if (args.Contains("-c", StringComparer.InvariantCultureIgnoreCase) || args.Contains("-console", StringComparer.InvariantCultureIgnoreCase))
{
service.StartService(args);
Console.ReadLine();
service.StopService();
return;
}
ServiceBase[] ServicesToRun = new ServiceBase[]
{
service
};
ServiceBase.Run(ServicesToRun);
}
StartService and StopService simply cause the OnStart and OnStop services to be redefined
source
share