Windows Service Development tutorial graphic tutorial debugging method

Source: Internet
Author: User
Document directory
  •  

Graphic tutorial

Http://www.cnblogs.com/itshare/archive/2012/04/22/2464969.html

 

Debugging method

Http://www.cnblogs.com/jack-liang/archive/2011/05/20/2051749.html

What is a Windows service?

Windows service applications are applications that require long-term running. They are especially suitable for server environments. It does not have a user interface and does not produce any visual output. Any user message is written into the Windows event log. When the computer starts, the service automatically starts running. They do not run only when users log on. They can run in any user environment including the system. Through the Service Control Manager, Windows Services are controllable and can be terminated, paused, and started as needed.

Create a Windows Service

The service we are about to create does nothing except demonstration.

When the service is started: register the entry information to a database to indicate that the service has been started.

When the service is running: regularly create a database project record at a specified interval.

When the service is stopped: Create the last database record.

This service automatically registers with the Windows Application log the records when it is successfully started or stopped.

 

 

Every time you need to modify the Windows Service, this requires you to uninstall and reinstall the service. However, it is a good habit to ensure that the service management console is closed before you uninstall the service. If this is not the case, you may encounter problems when uninstalling and re-installing Windows Services. If you only uninstall the service, you can run the InstallUtil command to log out of the service. However, you need to add a/u command to the end.

Debug Windows Services

From another perspective, debugging Windows Services is totally different from a common application. More steps are required to debug Windows Services. Services cannot be debugged as long as they are simply executed in the development environment as you do for common applications. The service must be installed and started first. We have done this in the previous section. To facilitate code tracing and debugging, once the service is started, you must use Visual Studio to append the running process (attach ). Remember, any modifications made to your Windows service must be uninstalled and reinstalled.

Append a running Windows Service

To debug the program, some operating instructions for the Windows Service are attached. These operations assume that you have installed the Windows service and it is running.

1. Use Visual Studio to load this project
2. Click the "debug" menu
3. Click the process menu.
4. Ensure that the system process is selected
5. In the list of available processes, locate the process on your Executable File Name and click to select it
6. Click the Add button.
7. Click OK.
8. Click Close.
9. Set a breakpoint in the timerreceivelapsed method and wait for it to execute

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.