最近用Quartz.net 做了一个定时任务处理程序.
按照网上的方法.配置如下.
在
Global.asax 文件中添加了下面的代码.
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
StartQuartz(); //启动定时
}
static IScheduler sched;
static StdSchedulerFactory schedulerFactory;
public static void StartQuartz()
{
if (sched == null)
{
var properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "DefaultQuartzScheduler";
properties["quartz.scheduler.instanceId"] = DateTime.Now.Ticks.ToString();
设置线程池
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";
远程输出配置
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "9999";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";
properties["quartz.scheduler.exporter.rejectRemoteRequests"] = "true";
//<!--properties["quartz.scheduler.proxy"] = "true";
//properties["quartz.scheduler.proxy.address"] = "tcp://127.0.0.1:5555/QuartzScheduler";-->
//properties["quartz.scheduler.proxy"] = "true";
//properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
//properties["quartz.jobStore.useProperties"] = "true";
//properties["quartz.jobStore.clustered"] = "true";
//properties["quartz.jobStore.misfireThreshold"] = "60000";
//<!--需要使用Quartz.MongoDB类库-->
//<!--properties["quartz.jobStore.type"] = "Quartz.Impl.MongoDB.JobStore, Quartz.Impl.MongoDB";-->
//<!--需要Quartz.Impl.AdoJobStore.JobStoreTX, Quartz类库-->
//properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
//properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
//properties["quartz.jobStore.dataSource"] = "myDS";
//<!--SqlServer
//properties["quartz.dataSource.myDS.connectionString"] = "Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Quartz.NET.mdf;Initial Catalog=SportsStore;Integrated Security=True";
//properties["quartz.dataSource.myDS.connectionString"] = "data source=MONOMATRIX\\SQLEXPRESS;initial catalog=quartznet;user id=sa;password=*****;multipleactiveresultsets=True;";
//properties["quartz.dataSource.myDS.provider"] = "SqlServer-20";
//<!--properties["quartz.dataSource.myDS.connectionString"] = "data source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Quartz.NET.mdf;Initial Catalog=SportsStore;Integrated Security=True";-->
//properties["quartz.dataSource.myDS.connectionString"] = "Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\project\Log\LogManager\LogManagerWebSite\App_Data\QuartzNet.mdf;Integrated Security=True";.
//<!--org.quartz.dataSource.myDS.driver = com.microsoft.jdbc.sqlserver.SQLServerDriver
//org.quartz.dataSource.myDS.URL = jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=quartzTest
//org.quartz.dataSource.myDS.user = sa
//org.quartz.dataSource.myDS.password = sa
//org.quartz.dataSource.myDS.maxConnections = 5
//properties["quartz.dataSource.myDS.provider"] = "SqlServer-20";
//<!--properties["quartz.dataSource.myDS.provider"] = "SqlServer-351"; SQLServerCe 这好几种,不知道为啥,应该是对应不同的数据库.
//properties["quartz.dataSource.myDS.provider"] = "SqlServer-352"; SQLServerCe
//properties["quartz.dataSource.myDS.provider"] = "SqlServer-400"; SQLServerCe -->
//<!--SQLServerCe
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
//properties["quartz.dataSource.myDS.provider"] = "SqlServerCe-351";-->
//<!--Postgre Npgsql-10
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.PostgreSQLDelegate, Quartz";
//properties["quartz.dataSource.myDS.provider"] = "Npgsql-10";-->
//<!--其它数据库配置见此类
//Oracle
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.OracleDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "OracleODPManaged-1123-40" />
//Oracle
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.OracleDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "OracleODPManaged-1211-40";
//Oracle
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.OracleDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "OracleODP-20";
//MySQL
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "MySql-50";
//MySQL
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "MySql-51";
//MySQL
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "MySql-65";
//MySQL
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "MySql-10";
//MySQL
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "MySql-109";
//SQLite
//properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz"/>
//properties["quartz.dataSource.myDS.provider"] = "SQLite-10";
//-->
schedulerFactory = new StdSchedulerFactory(properties);
sched = schedulerFactory.GetScheduler();
sched.Start();
Debug.WriteLine("StartQuart at " + DateTime.Now.ToString());
}
}
然后配置了一个 crystalQuartz 悲剧的是:
怎么弄都提示下面的错误.
无奈.
Could not initialize scheduler
Scheduler with name ‘DefaultQuartzScheduler’ already exists.
这段代码在Winform 代码中是可以正常使用的.亲测无问题.
不知道为什么到了.asp.net mvc以后 就出错了
找遍了网上的文章.也没办法.解决..
后来抱着试试看的态度..
把
properties[“quartz.scheduler.instanceName”] = “DefaultQuartzScheduler”;
properties[“quartz.scheduler.instanceId”] = DateTime.Now.Ticks.ToString();
这两行注释掉.竟然可以了…..