1. MSDN Recommended Methods
1.1, debugging the initialization of Windows services, startup
Write another program to programmatically initialize and start a service
Note: Log in OnStart, OnStart to return in 30 seconds. Otherwise, the boot will fail! So don't put too much code in the OnStart! You can use asynchronous or thread.
1.2. Debugging other aspects of Windows services
1 Installation of your service: Intallutils Xx.exe
2 The service can be started from the Service Control Manager, Server Explorer, or code
3 vs: Set the relevant breakpoint, start debugging, and then select Debug-> in the toolbar to attach to the process ..., select your service, OK.
2, Trace method
2.1, add debugging methods
private static void DebugRun(string[] args)
{
/*
初始化服务
OnStart();
Console.ReadLine();
OnStop();
*/
}
2.2. The entry of the rewriting procedure is as follows:
public static void Main(string[] args)
{
#if DEBUG
DebugRun(args);
#else
/*
初始化服务
*/
#endif
}
2.3, add 2 kinds of debugging code
EventLog.WriteEntry("...");
System.Diagnostics.Debug.WriteLine("...");