在Windows定時作業中,其實有多種關於作業調度形式,比如Windows Services 和 Windows Form 都可以做到,各有各的好處。現在來介紹下使用插件的形式進行定時作業。
1、用quartz.net插件,Quartz是源自於JAVA的一個很好用的插件,移植到.NET平台后表現很不錯,但是有一定的缺陷就是配置比較繁瑣,但網上的教程其實是最多的,
官網:http://quartznet.sourceforge.net/
相關教程 http://www.cnblogs.com/lzrabbit/archive/2012/04/15/2448326.html
2、hangfire 插件,HangFire其實很優秀,配置灰常簡單
http://docs.hangfire.io/en/latest/quick-start.html
1)下載 Hangfire 插件,並安裝
2)創建Startup類代碼如下。
partial class Startup { public void Configuration(IAppBuilder app) { app.UseHangfire(config => { config.UseSqlServerStorage(@"Data Source=XXX;Initial Catalog=Hangfire;User ID=xxx;Password=xxx"); config.UseServer(); }); RecurringJob.AddOrUpdate(() => Test(), Cron.Minutely); } //寫入作業 public void Test() { //------ } }
啟動后可以在 http://<your-site>/hangfire 里面進行查看日志和管理。
未完待續····