using Quartz; using Quartz.Xml; using System; using System.Collections; using System.IO; using System.ServiceProcess; using System.Threading; namespace WX.CRM.DataProceService { public partial class DataProceService : ServiceBase { Thread _smsSend; public DataProceService() { InitializeComponent(); } protected override void OnStart(string[] args) { try { _smsSend = new Thread(new ThreadStart(GetScheduleJob)); _smsSend.Start(); Common.LogHelper.Info("服务已启动!"); } catch (Exception e) { Common.LogHelper.Error(string.Concat("DataProceService.OnStart:", e.ToString())); } } protected override void OnStop() { try { if (_smsSend.ThreadState == System.Threading.ThreadState.Running) _smsSend.Abort(); WX.CRM.Common.LogHelper.Info("服务停止!"); } catch (Exception ex) { WX.CRM.Common.LogHelper.Error("服务停止异常" + ex.Message + ex.StackTrace); } } public void GetScheduleJob() { try { var processor = new JobSchedulingDataProcessor(true, true); ISchedulerFactory sf = new Quartz.Impl.StdSchedulerFactory(); IScheduler sched = sf.GetScheduler(); Stream s = new StreamReader(string.Concat(AppDomain.CurrentDomain.BaseDirectory, "XML/JobConfig.xml"), System.Text.Encoding.GetEncoding("UTF-8")).BaseStream; processor.ProcessStream(s, null); processor.ScheduleJobs(new Hashtable(), sched, false); sched.Start(); } catch (Exception ex) { WX.CRM.Common.LogHelper.Error(string.Concat("DataProceService.GetScheduleJob:", ex.Message, ex.StackTrace)); } } } }