Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Introduction to Windows Service applications
Microsoft Windows Services (that is, previous NT services) enable you to create executable applications that can run for a long time in their own Windows sessions. These services can be started automatically when the computer is started, can be paused and restarted, and no user interface is displayed. This makes the service ideal for use on the server, or at any time, in order not to affect other users working on the same computer and require long running features. You can also run services in the security context of a specific user account or a default computer account that is different from the logged-on user.
Creating Windows Services
When you create a service, you can use the Visual Studio. NET project template called Windows Services. 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 stop request, or false to prohibit the service from stopping.
CanShutdown True indicates that the service wants to be notified when the computer that is running it shuts down so that the OnShutdown procedure can be invoked.
CanPauseAndContinue True indicates that a service will accept a request to suspend or continue to run, or false to prohibit a service from pausing and continuing.
Canhandlepowerevent 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.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
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:
and provide relevant evidence. A staff member will contact you within 5 working days.