Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop C # Windows service program

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to develop C # Windows service programs". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to develop C# Windows service programs.

Rapid development of C#Windows service programs: in many applications, windows services are needed to operate databases and other operations, such as

(1) some very slow database operations do not want to be done at once, but slowly through the service schedule, such as scheduled database backup, etc.

(2) use windows service to do Host in. Net Remoting

With vs.net, we can build its windows service in a few minutes. It's very simple.

Here are the steps for the rapid development of C#Windows service programs

Rapid development of C#Windows service programs 1. Create a new project

Rapid development of C#Windows service programs 2. Select the Windows service from a list of available project templates

Rapid development of C#Windows service programs 3. The designer opens in design mode

Rapid development of C#Windows service programs 4. Drag a Timer object from the component list in the toolbox onto the design surface (note: be sure to use Timer from the component list and not from the Windows forms list)

Rapid development of C#Windows service programs 5. Set Timer property, Interval property 200ms (5 database operations per second)

Rapid development of C#Windows service programs 6. Then add functions to the service

Rapid development of C#Windows service programs 7. Double-click the Timer and write some code for database operations in it, such as

SqlConnection conn=new SqlConnection (server=127.0.0.1;database=test;uid=sa;pwd=275280 "); SqlCommand comm=-new SqlCommand (insert into tb1 ('111), conn); conn.Open (); comm.ExecuteNonQuery (); conn.Close ()

Rapid development of C#Windows service programs 8. Switch the service to design view

Rapid development of C#Windows service programs 9. Right-click in Design view and select add installer

Rapid development of C#Windows service programs 10. Switch to the design view of the ProjectInstaller that was just added

Rapid development of C#Windows service programs 11. Set the properties of the serviceInstaller1 component:

1) ServiceName = My Sample Service

2) StartType = Automatic (automatic operation on boot)

Rapid development of C#Windows service programs 12. Set the property Account = LocalSystem of the serviceProcessInstaller1 component

Rapid development of C#Windows service programs 13. Change the path to the bin\ Debug folder where your project is located (in the bin\ Release folder if you are compiling in Release mode)

Rapid development of C#Windows service programs 14. Execute the command "InstallUtil.exe MyWindowsService.exe" to register the service so that it creates an appropriate registry key. (InstallUtil this program is under the WINDOWS folder\ Microsoft.NET\ Framework\ v1.1.4322)

Rapid development of C#Windows service programs 15. Right-click "my computer" on the desktop and select "manage" to click the computer management console

Rapid development of C#Windows service programs 16. In the "Services" section of "Services and applications", you can find that your Windows service is already included in the service list.

17. Right-click your service selection to start your service.

Check to see if the database has five more records per second.

The rapid development of C#Windows service programs needs to pay attention to:

If you modify the service, there is no need to re-register the service if the path does not change. If the path changes, you need to uninstall the service InstallUtil.exe / u parameter first, and then reinstall the service. You cannot install the service directly. Also, the windows service has no interface, so don't try to output some information in a controlled way, you can only add an EventLog and write the log through WriteEntry ().

Thank you for your reading, the above is the content of "how to develop C # Windows service programs". After the study of this article, I believe you have a deeper understanding of how to develop C # Windows service programs, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 228

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report