public partial class MyService : ServiceBase { private ISchedulerFactory schedulerFactory; private JobSchedulingDataProcessor processor; private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MyService));
public MyService() { InitializeComponent();
schedulerFactory = new StdSchedulerFactory(); processor = new JobSchedulingDataProcessor(true, true); }
protected override void OnStart(string[] args) { try { IScheduler scheduler = schedulerFactory.GetScheduler(); string fileName = AppDomain.CurrentDomain.BaseDirectory + System.Configuration.ConfigurationManager.AppSettings["JobConfigFile"]; processor.ProcessFile(fileName, null); processor.ScheduleJobs(new Hashtable(), scheduler, false);
scheduler.Start();
logger.Info("service started ok"); } catch (Exception ex) { logger.Error("service started fail", ex); } }
protected override void OnStop() { try { IScheduler scheduler = schedulerFactory.GetScheduler(); scheduler.Shutdown(true);
logger.Info("service stopped ok"); } catch (Exception ex) { logger.Error("service stopped fail", ex); } }
三步实现任务public class MyTask : IJob { #region IJob Members
public void Execute(JobExecutionContext context) {
//todo }
#endregion }
其实只要实现iJob接口即可。 更多的关于Quartz.net的资料请看 http://www.openbeta.cn/quartznet.ashx http://www.cnblogs.com/shanyou/category/102991.html 在这里你可以得到最新的进展和源码 http://quartznet.sourceforge.net/ 上面代码片段的完整示例,请在 这里下载 shore 2008-02-27 18:23 发表评论转载于:https://www.cnblogs.com/hotsoho.net/archive/2008/02/27/1206554.html
相关资源:Quartz.NET 官方最新源码及Demo