topshelf可以很简单方便的实现windows service服务,详见我的一篇博客的介绍

http://www.cnblogs.com/xiaopotian/articles/5428361.html

Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等。 Quartz.NET允许开发人员根据时间间隔(或天)来调度作业。它实现了作业和触发器的多对多关系,还能把多个作业与不同的触发器关联。整合了 Quartz.NET的应用程序可以重用来自不同事件的作业,还可以为一个事件组合多个作业。Quartz.NET是OpenSymphony的开源项目。Quartz.Net 是Quartz的C#移植版本。

它一些很好的特性:

1:支持集群,作业分组,作业远程管理。 

2:自定义精细的时间触发器,使用简单,作业和触发分离。

3:数据库支持,可以寄宿Windows服务,WebSite,winform等。

下面是官网的详细介绍http://www.quartz-scheduler.net/documentation/index.html

结合topshelf、log4net与官网案例写了一个小的demo

第一步,实现IJob

 1 /// <summary>
 2     /// A sample job that just prints info on console for demostration purposes.
 3     /// </summary>
 4     public class SampleJob : IJob
 5     {
 6         //private static readonly ILog logger = LogManager.GetLogger(typeof(SampleJob));
 7 
 8         /// <summary>
 9         /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
10         /// fires that is associated with the <see cref="IJob" />.
11         /// </summary>
12         /// <remarks>
13         /// The implementation may wish to set a  result object on the 
14         /// JobExecutionContext before this method exits.  The result itself
15         /// is meaningless to Quartz, but may be informative to 
16         /// <see cref="IJobListener" />s or 
17         /// <see cref="ITriggerListener" />s that are watching the job's 
18         /// execution.
19         /// </remarks>
20         /// <param name="context">The execution context.</param>
21         public void Execute(IJobExecutionContext context)
22         {
23             LogHelper.Info("SampleJob running...");
24             //Thread.Sleep(TimeSpan.FromSeconds(5));
25             Console.WriteLine("111111111111111111111");
26             LogHelper.Info("SampleJob run finished.");
27         }
28     }
View Code

相关文章: