Developing Windows services under. Net

Source: Internet
Author: User

Creating Windows Services

--------------------------------------------------

When you create a service, you can use a Visual Studio.NET project template called a Windows service. This template automatically completes most of your work by referencing the appropriate classes and namespaces, setting inheritance from the service base class, and overriding several methods that you might want to rewrite.

To create a functional service, you must at least:

Sets the ServiceName property.

Create the necessary installers for the service application.

Override the OnStart and OnStop methods and specify code for them to customize how the service behaves.

After you add the installer to your application, the next step is to create the Setup project, which installs the compiled project files and runs the installer that is required to install the service. To create a complete Setup project, you must add the output of the service project to the Setup project, and then add a custom action to install your service.

Create a Windows service project.

In the Properties window, set the ServiceName property for the service. (Note that the value of the ServiceName property must always match the name of the record in the installer class.) If you change this property, you must also update the ServiceName property in the Installer class. )

Set all of the following properties to determine the working mechanism of the service.

canstop true indicates that the service will accept a request to stop running; False indicates that a service stop is prohibited.
canshutdown true table The service expects to be notified when the computer that is running it shuts down so that the OnShutdown procedure can be invoked.
true indicates that the service will accept a request to suspend or continue to run, or false to prohibit the service from pausing and continuing.
true indicates that the service can handle notifications about changes to the power state of the computer; False indicates that the service is not notified about these changes.
autolog true indicates that the service Writing an information item to an application's event log when an action is performed; False indicates that this feature is disabled. (Note that the default is true.)

Note that when CanStop or CanPauseAndContinue is set to false, the Service Control Manager disables the stop,The appropriate menu options for pausing or continuing the service.

Access the Code Editor and fill in the required processing for the OnStart and OnStop procedures.

Override all other methods for which you want to define functionality.

Add the installer that is required for the service application.

Build the project by choosing build Solution from the Build menu. (Note that you do not have to run the project by pressing the F5 key to run the service project in this way.) )

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.