如何在ASP.NET中使用Quartz.net

ACP*_*ACP 72 asp.net quartz.net

我不知道如何在ASP.NET中使用Quartz.dll.在哪里编写用于调度作业的代码,以便每天早上触发邮件?如果有人知道它,请帮助我...

编辑:我发现如何以PRO方式使用Quartz.NET?真的很有用.

jvi*_*lta 77

您有几个选择,具体取决于您想要做什么以及如何设置它.例如,您可以将Quartz.Net服务器安装为独立的Windows服务器,也可以将其嵌入到asp.net应用程序中.

如果你想嵌入它,那么你可以从你的global.asax开始服务器,就像这样(来自源代码示例,示例#12):

NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "RemoteServer";

// set thread pool info
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";

ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
sched.Start();
Run Code Online (Sandbox Code Playgroud)

如果您将其作为服务运行,您将像这样远程连接到它(来自示例#12):

NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "RemoteClient";

// set thread pool info
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";

// set remoting expoter
properties["quartz.scheduler.proxy"] = "true";
properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
// First we must get a reference to a scheduler
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
Run Code Online (Sandbox Code Playgroud)

一旦你有一个对调度程序的引用(无论是通过远程处理还是因为你有一个嵌入式实例),你可以安排这样的工作:

// define the job and ask it to run
JobDetail job = new JobDetail("remotelyAddedJob", "default", typeof(SimpleJob));
JobDataMap map = new JobDataMap();
map.Put("msg", "Your remotely added job has executed!");
job.JobDataMap = map;
CronTrigger trigger = new CronTrigger("remotelyAddedTrigger", "default", "remotelyAddedJob", "default", DateTime.UtcNow, null, "/5 * * ? * *");
// schedule the job
sched.ScheduleJob(job, trigger);
Run Code Online (Sandbox Code Playgroud)

这里是我为Quartz.Net开始的人写的一些帖子的链接:http://jvilalta.blogspot.com/2009/03/getting-started-with-quartznet-part-1.html