zoukankan      html  css  js  c++  java
  • C#做后台运行的服务,并添加安装程序

    1 新建windows 服务项目

    2 注意加载timer的时候需要加载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.timer1_Tick);

        //this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

        // 

        // DataTransfer_Service

        // 

        this.CanShutdown = true;

        this.ServiceName = "DataTransfer_Service";

        ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();

    3 到服务的设计界面,右击选择添加安装程序,项目里面自动添加了ProjectInstaller.cs这一项,到设计界面

      有serviceInstaller1和serviceProcessInstaller1两个控件

      将serviceInstaller的StartType设置为Automatic

      将serviceProcessInstaller1的Account设置为LocalSystem

    4 添加项目,选择【其他项目类型】下的【安装和部署】

      在项目属性页里面,点击项目必备...

      在指定系统必备组件的安装位置下

      选择 从与我的应用程序相同的位置下载系统必备组件

    5 点击文件系统编辑器

      右击【应用程序文件夹】,添加项目输出,选择主输出,配置为(活动)

      然后再添加config文件

    6 用户的“程序”菜单和用户桌面可以添加快捷方式

    7 自定义操作编辑器

      在安装、提交、回滚、卸载操作下都添加应用程序文件夹下的主输出

    8 配置完毕,编译项目文件

    9 在安装项目下的debug文件夹下生成了安装文件,直接运行即可安装

    10 如果程序里面用了安装目录下的日志或者是读入了文件,需要在安装目录下添加相应的文件

    11 好!直接运行后台服务就可以了

  • 相关阅读:
    POJ1661 Help Jimmy
    POJ2533 Longest ordered subsequence
    数字三角形
    第四章 指令系统
    栈和队列
    第三章 存储器的层次结构
    线性表—概念总结及代码示例
    数据的表示和运算
    计算机系统概述
    树-概念性总结及代码示例
  • 原文地址:https://www.cnblogs.com/myparamita/p/2185018.html
Copyright © 2011-2022 走看看