zoukankan      html  css  js  c++  java
  • 添加服务,用于定期执行某个程序或者应用程序(windows service)

    需要配合window的安装程序一起写






    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using Inspur.DataExchange.Logging; using System.Configuration; using Inspur.Finix.ExceptionManagement; namespace WenZhouZJ.Exchange.FromNW { public partial class Service1 : ServiceBase { private System.Timers.Timer timer2; public Service1() { this.timer2 = new System.Timers.Timer(); ((System.ComponentModel.ISupportInitialize)(this.timer2)).BeginInit(); this.timer2.Enabled = true; this.timer2.Interval = 1 * 1000; this.timer2.Elapsed += new System.Timers.ElapsedEventHandler(this.timer2_Elapsed); ((System.ComponentModel.ISupportInitialize)(this.timer2)).EndInit(); this.ServiceName = "温州质监与南威数据交换_收件信息获取服务"; } protected override void OnStart(string[] args) { //this.timer1.Enabled = false; } protected override void OnStop() { this.timer2.Enabled = false; } private void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //如果到了设置的运行时间 string runtime = ConfigurationSettings.AppSettings["Runtime"]; if (string.IsNullOrEmpty(runtime) || runtime.Equals(DateTime.Now.ToString("HH:mm"))) { this.timer2.Enabled = false; try { //DataExchange.DoExchange(); 定期执行的事件 } catch (Exception ex) { ExceptionManager.Handle(ex); } this.timer2.Interval = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["Interval"]) * 60 * 1000; this.timer2.Enabled = true; } } } }


  • 相关阅读:
    剑指 Offer——13. 调整数组顺序使奇数位于偶数前面
    剑指 Offer——3. 从尾到头打印链表
    剑指 Offer——2. 替换空格
    剑指 Offer——1. 二维数组中的查找
    LeetCode 905. Sort Array By Parity 按奇偶校验排列数组
    LeetCode 448. Find All Numbers Disappeared in an Array找到所有数组中消失的元素
    SSH 代码笔记
    anaconda3安装caffe
    opencv多版本安装
    人脸文章与数据库
  • 原文地址:https://www.cnblogs.com/wenghaowen/p/3863025.html
Copyright © 2011-2022 走看看