debugging Windows Service in VS 2005

Source: Internet
Author: User

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("...");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.