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工具来安装。

  • 相关阅读:
    redis 基本指令
    php 魔术变量
    php 常用函数总结
    linux 命令——3 pwd (转)
    linux 命令——2 cd (转)
    linux 命令——ls
    ffmeg过滤器介绍[转]
    最简单的基于FFMPEG的转码程序 —— 分析
    ffmpga结构体和常用函数(总结)
    leetcode--3
  • 原文地址:https://www.cnblogs.com/Benjamin/p/3638893.html
Copyright © 2011-2022 走看看