using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; namespace CB.WService.CatchLotteryData { public partial class CatchLotteryDataService : ServiceBase { public CatchLotteryDataService() { InitializeComponent(); } protected override void OnStart(string[] args) { var config = CB.LotteryCatchData.Config.CatchDataConfigs.GetConfig(); if (null == config || null == config.List) { CB.Common.FileUtil.WriteLog("配置文件无效"); return; } timer1.Interval = config.Interval; timer1.Enabled = true; } protected override void OnStop() { timer1.Enabled = false; } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { timer1.Enabled = false; DateTime startTime = DateTime.Now; var config = CB.LotteryCatchData.Config.CatchDataConfigs.GetConfig(); if (null == config || null == config.List || 0 >= config.List.Count) { CB.Common.FileUtil.WriteLog("配置文件无效"); timer1.Enabled = false; return; } foreach (var item in config.List) { try { CB.LotteryCatchData.CatchData.CatchLotteryData(item); } catch (Exception ex) { CB.Common.FileUtil.WriteLog(string.Format(item.Name + "抓取异常:{0} \r\n", ex)); } } timer1.Enabled = true; } } }