Created
August 29, 2011 19:29
-
-
Save ferventcoder/1179173 to your computer and use it in GitHub Desktop.
Debugging Windows Services
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
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(); | |
} | |
} |
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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also make sure in Properties -> Application -> Output type: is set to
and
Startup object: is set to