关于C#消息调度(作业日志)

在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        里面进行查看日志和管理。

未完待续····

原文地址:https://www.cnblogs.com/albert-struggle/p/4390803.html