. NET development of windows Services

Source: Internet
Author: User
Tags net command

Recently, three-party State synchronization is required for projects, that is, PDM, CAD, and instant messaging tools, because these tools are not developed in one language. So how to do this is troublesome. The database-based monitoring is affirmative. How can we complete this monitoring? I first designed the monitoring system process and added the database judgment, but this will affect the performance of the software. So I thought of using system services to complete this transfer. Of course, it is just an assumption that it is still unknown whether it can be completed.
Open the C # project, find the windows Service Project, and create a new one. The design interface is the form of components. Go to the Code view: Wow, all written:
Three functions provided by the system: Main, Start, and Stop
Write a test function:
Private void WriteLog (string content)
{
String fPath = @ "d: \ Windows service \ log.txt ";
StreamWriter sWriter = null;
If (! File. Exists (fPath ))
File. Create (fPath );
Try
{
SWriter = new StreamWriter (fPath, true );
SWriter. WriteLine (content );
}
Catch (System. Exception err)
{
Throw new Exception ("service write error", err );
}
Finally
{
SWriter. Close ();
}

}
Add it to the start function to generate it. Run ----> the prompt cannot be executed directly. The Installer is required.
No way. I checked it online.
Originally, right-click the Component Interface and choose --> Add installation project. OK.
Set properties according to the online settings:
Set the properties of the serviceInstaller1 component:
1) ServiceName = My Sample Service
2) StartType = Automatic
Set the properties of the serviceProcessInstaller1 component
1) Account = LocalSystem
Run installutil.exe to register the instance. Enter the InstallUtil service name .exe at the. net command prompt.
Indicates that the registration is successful.
Find the service you just registered in service management.
BackD: \ WindowsService \ log.txt View
The "Service Startup..." information is added.
Haha, I tried the windows service for the first time. I don't know if I can play a proper role in reality.

 

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.