zoukankan      html  css  js  c++  java
  • 创建需要计时器的windows service

    1、在VS中建立windows service后,应该添加一个安装程序。

    2、在默认的Service1.cs设计界面右键,添加安装程序,生成ProjectInstaller。包含两个类serviceProcessInstaller和serviceInstaller。

    3、前者的属性Account一般应设为LocalSystem。

    4、如需要计时器,不应使用winform的计时器,而是System.Timers.Timer。

    于是在Service1.cs中

    添加私有变量:

     private System.Timers.Timer timer;

    然后在初始化时:

      private void InitializeComponent()
            {
                this.timer = new System.Timers.Timer();
                ((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();
                // 
                // timer
                // 
                this.timer.Enabled = true;
                this.timer.Interval = 120000D; //循环时间,单位毫秒
                this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.aTimer_Elapsed);
                // 
                // iLearningPush
                // 
                this.ServiceName = "myService";
                ((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();
    
            }

    5、Service1的属性ServiceName为部署后的服务名称

    6、windows服务需要InstallUtil工具来安装。

  • 相关阅读:
    触发器(2)
    触发器
    GZipStream
    MemoryStream类读写内存
    ashx一般处理程序
    Redmin 一键安装
    Unity3D和网页数据交互的基本原理
    apk MIME类型
    [leetcode]Valid Sudoku
    [leetcode]Search in Rotated Sorted Array
  • 原文地址:https://www.cnblogs.com/Benjamin/p/3638893.html
Copyright © 2011-2022 走看看