Some experiences in debugging Windows service programs

Source: Internet
Author: User

During the past two weeks, a Windows Service was developed using vs2005.Program. I have also helped my colleagues debug the service program. But the general feeling is that debugging Windows service is more troublesome than debugging web service. Using the following techniques makes debugging easier:

1. Using Visual Studio 2005 command prompt to run commands is more efficient than using the installation package. It eliminates the need for installation packages, uninstallation, and installation.

2. Run the following command in Visual Studio 2005 Command Prompt:

1) install service: installutil yourservice.exe

2) uninstall service installutil/u yourservice.exe

If the service is running, the command will stop serive and uninstall it.

3) Start Service Net start "your service"

"Your service" is the value of system. serviceprocess. serviceinstaller. servicename in the projectinstaller class. It is the service name that you can see in the Service Manager.

3. debug the service to start Visual Studio 2005 and open your yourservice project. Select "debug-> attach to process ...".

Attach yourserice.exe in the attach to process window. If you cannot see yourserice.exe, select "show processes from all users ". in this way, you can see the service running with the system account. if you have set a breakpoint, when serice runs to the breakpoint you set, the program will stop waiting for your debugging.

4.to ensure that yourservice.exe can be customized, yourservice.exe must be compiled in debug mode.

5. AboutCodeDebugging.

Windows serice must be started within 30 seconds, but you cannot see it in the attach to process window before the service starts. There is a trick to write code here -- set system. Timers. Timer In onstare (), and then use timer to delay starting commercial services. The delay time is determined by the time you enter the debugging status. It can be set to 5 seconds. Using timer delay to start commercial services can also avoid Service Startup failure due to long business processing logic at startup.

Timer should be stopped after commercial services are started (set timer. Enable = false ).

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.