Windows Service Development
I. Development
1. Create a new Windows Service Project in vs2008. I name it wxjdjcj.
2. For the sake of cleanliness, the default service1.cs is deleted, and a new Windows service item is added, named djservicegetdatafromcj.
3. Next, add a timer control component to the djservicegetdatafromcj designer. The timer control here is in the component column, not in Windows form. Here we can
It is identified by timer events, that is, the lightning mark on the click attribute. If it is click, it indicates that it is Windows form, and if it is elapsed, it is component. If none of the components exist
Add this component by selecting items in the toolbox. The naming control is system. Timers. Timer.
4. Double-click the timer component to add the required services to the cjtimer_elapsed event. The business I need is to regularly fetch data from the database and insert it into another database.
5. Set the timer attribute and set it to true at enabled to ensure that the timer control can be used. This is critical, otherwise it will not work. Set interval to 5000, which will be performed in five seconds.
One event in elapsed.
6. Right-click the "design view" of the service and select "add installer ".
7. Switch to serviceinstaller and set its property: servicename = djservicegetdatafromcj, which is used to indicate the name of the system service. Starttype = automatic, this is
Auto Start. Start with the system.
8. Switch to serviceprocessinstaller to set its attributes: account = LocalSystem
9. Compile. You can find the Windows Service wxjdjcj.exe in the bin \ debugdirectory, but you cannot double-click it to run it.
2. Deployment
The deployment can also be said to install Windows service. There are two methods:
First, use the installutil.exe program under. Net framework. we can install our service through the command prompt in Start> program> visual studio2008> visual studiotool. Installutil.exe wxjdjcj.exe, right-click my computer and manage the services to start our services. The Stop command net stop djservicegetdatafromcj, because the service name I set here is djservicegetdatafromcj. The delete service is installutil.exe/u wxjdjcj.exe. Here, we need to differentiate the uninstallation of General Windows Services. General uninstallation: delete SC wxjdjcj.
The second is to add a project under the solution through the Installation Wizard provided by Vs, select the installer from other projects, and add the main output in the application folder, then we added our wxjdjcj project, which is not enough because we only output the content to a directory. We also need to use the View> editor> Custom operation to add the main output project to each step. Then compile the installer. Find the installer in its bin \ DEBUG directory. After installation, you can see it in the system service and start the service.
OK.