Microsoft Windows Services (that is, previous NT services) enable you to create executable applications that can run for long periods of time in their own Windows sessions. These services can be started automatically when the computer starts, can be paused and restarted, and does not display any user interface. 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, which requires long-running functionality. You can also run a service in a different security context than a specific user account or a default computer account that is a logged-on user.
Below we complete a Windows service to periodically insert records into the MySQL database, come on!
1: Create Project
2: Code
3: Set cycle time
Write a method for inserting MySQL data
4: Create the Installer
Step Five: Install
Installation commands
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\PageRequestService\PageRequestService.exe
Uninstall command
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\PageRequestService\PageRequestService.exe-u
In Control Panel---Administrative tools-----Services----Right-click----Start Services
Step Six: Register batch files
The batch initialization and uninstallation files are included in the project for easy deployment, and the newer I set is assigned so that if there is a change, he will automatically copy to the Bin/debug directory by default.
(Thebin directory is used to save the project post-build assembly, it has Debug and release two versions, respectively, the corresponding folders are Bin/debug and bin/release, this folder is the default output path, We can modify it by: Project Properties-> Configuration Properties-> Output path.
The obj directory is used to save the compiled results for each module, in the . NET, the compilation is divided into modules, and the compilation will be merged into one after completion . DLL or . EXE is saved to the bin directory. Because incremental compilation is the default at compile time, which means that only the changed modules are recompiled,obj saves the compilation results of each module to speed up the compilation. Whether to use incremental compilation, you can set it by: Project Properties-> Configuration Properties-> Advanced-> Incremental Compilation. )
Find data inserted in the database, of course, can register the service for automatic
Seventh step: Let's go deeper and call our Windows service in another module
Original, a long time ago notes, slowly will put their previous notes in the blog Park released. The lack of hope to give some advice!
Windows Services-hands-on experience with you