標籤:blog os 資料 io art re
需要配合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; } } }}