1. Create a Windows Service Project
2. When loading timer, you must load system. Timers. Timer.
This. timer1 = new system. Timers. Timer ();
(System. componentmodel. isupportinitialize) (This. timer1). begininit ();
//
// Timer1
//
This. timer1.interval = 5000;
This. timer1.elapsed + = new system. Timers. elapsedeventhandler (this. timerttick );
// This. timer1.tick + = new system. eventhandler (this. timerw.tick );
//
// Datatransfer_service
//
This. canshutdown = true;
This. servicename = "datatransfer_service ";
(System. componentmodel. isupportinitialize) (This. timer1). endinit ();
3. On the service design page, right-click and select add installer. The project automatically adds projectinstaller. CS to the design page.
There are two controls: serviceinstaller1 and serviceprocessinstaller1.
Set starttype of serviceinstaller to automatic
Set the account of serviceprocessinstaller1 to LocalSystem
4. Add a project and select "Install and deploy" under "Other project types]
On the project properties page, click required items...
In the installation location of the required system components
Select to download necessary system components from the same location as my application
5. Click file system editor.
Right-click Application folder, add project output, select main output, and configure to (active)
Then add the config file.
6. You can add shortcuts to the user's "program" menu and user desktop.
7. Custom operation Editor
Add the main output in the application folder to the installation, submission, rollback, and uninstallation operations.
8. After the configuration is complete, compile the project file.
9. Create an installation file in the debug folder of the installation project and run it directly to install it.
10 if logs in the installation directory are used in the program or files are read, you must add the corresponding files in the installation directory.
Good 11! Run the background service directly.