Quartz.NET笔记(一) 概述

配置

有三种配置方式:

1.编码方式: scheduler factory提供的NameValueCollection参数

2.使用标准的 youapp.exe.config配置文件中的quartz-element

3.应用程序根目录中的quartz.config配置文件

注意:VS中要将配置文件设置为“Copy always”

一个简单的例子:

Program.cs

 1 using System;
 2 using System.Threading;
 3 
 4 using Quartz;
 5 using Quartz.Impl;
 6 
 7 namespace ConsoleApplication1
 8 {
 9     public class Program
10     {
11         private static void Main(string[] args)
12         {
13             try
14             {
15                 // Grab the Scheduler instance from the Factory 
16                 IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
17 
18                 // and start it off
19                 scheduler.Start();
20 
21                 // some sleep to show what's happening
22                 Thread.Sleep(TimeSpan.FromSeconds(60));
23 
24                 // and last shut down the scheduler when you are ready to close your program
25                 scheduler.Shutdown();
26             }
27             catch (SchedulerException se)
28             {
29                 Console.WriteLine(se);
30             }
31         }
32     }
33 }

一旦使用StdSchedulerFactory.GetDefaultScheduler()一个scheduler ,应用程序默认将不会终止,直到调用scheduler.Shutdown()方法,因为那样会激活线程(非守护线程)。

现在运行程序,不会显示任何东西,60秒过后,程序终止。

Adding logging

  Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter { Level = Common.Logging.LogLevel.Info };

原文地址:https://www.cnblogs.com/hzz521/p/5155479.html