using System; using System.ServiceProcess; using Hangfire; namespace Quanjiang.DigitalScholl.JobService { public partial class QuanjiangDigitalSchollJobService : ServiceBase { private BackgroundJobServer _server; public QuanjiangDigitalSchollJobService() { InitializeComponent(); GlobalConfiguration.Configuration.UseSqlServerStorage("HangfireConnString"); } protected override void OnStart(string[] args) { var options = new BackgroundJobServerOptions { ServerName = "QuanjiangDigitalSchollJobService" }; _server = new BackgroundJobServer(options); //自动运行连接考勤机 RecurringJob.Trigger("HKAttendance"); } protected override void OnStop() { _server.Dispose(); } } }