C # provide services running in the background and add the installer

Source: Internet
Author: User

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.

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.