如何在 ASP.NET 中使用 Quartz.net [英] How to use Quartz.net with ASP.NET

查看:29
本文介绍了如何在 ASP.NET 中使用 Quartz.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I don't know how to use Quartz.dll in ASP.NET. Where to write the code for scheduling jobs to trigger mail every morning? Please if some body knows about it plz help me...

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

I found HOW TO use Quartz.NET in PRO way? to be really useful.

推荐答案

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

You have a couple of options, depending on what you want to do and how you want to set it up. For example, you can install a Quartz.Net server as a standalone windows serviceor you can also embed it inside your asp.net application.

如果您想以嵌入式方式运行它,那么您可以从 global.asax 中启动服务器,如下所示(来自源代码示例,示例 #12):

If you want to run it embedded, then you can start the server from say your global.asax, like this (from the source code examples, example #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();

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

If you run it as a service, you would connect remotely to it like this (from example #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();

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

Once you have a reference to the scheduler (be it via remoting or because you have an embedded instance) you can schedule jobs like this:

// 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);

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

Here's a link to some posts I wrote for people getting started with Quartz.Net: http://jvilalta.blogspot.com/2009/03/getting-started-with-quartznet-part-1.html

这篇关于如何在 ASP.NET 中使用 Quartz.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆