如何设置Quartz.NET调度电子邮件 [英] How to setup Quartz.NET for scheduling Emails

查看:164
本文介绍了如何设置Quartz.NET调度电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两种解决方案 Quartz.server.2008.sln quartz.2008.sln 在下载quartz.NET库。现在,我必须安装循环作业。会有表中,所有的时间表将被定义的数据库(如每月的第一个星期五,每次5月份,每个星期日上午12点...等)。我按时间表执行的方法。现在,我如何使用quartz.net从数据库中获取日程安排并设置执行方法?什么是正确的步骤是什么?

There are two solutions Quartz.server.2008.sln and quartz.2008.sln in the downloaded quartz.NET library. Now I have to setup recurring job. There would be table in the database where all schedules will be defined (like first friday of the month, each 5 in month, each sunday 12 am...etc). I have the method executed on schedule. Now how can i use quartz.net to get schedule from database and set the method to execute? what are the proper steps?

推荐答案

我觉得你可以创建在后台运行的Windows服务。你可以阅读 scheduleFromDatabase varaible从数据库中,然后把它传递给石英。

I think you can create a windows service running in background. You can read the scheduleFromDatabase varaible from database and then pass it to Quartz.

这是从一个控制台应用程序的一个小例子:

This is a small example from a console app:

    static void Main(string[] args)
    {
        ISchedulerFactory schedFact = new StdSchedulerFactory();

        IScheduler sched = schedFact.GetScheduler();
        sched.Start();

        JobDetail jobDetail = new JobDetail("myJob", null, typeof(HelloJob));

        //read this string from database
        string scheduleFromDatabase="0 11 16 ? * FRI,SUN";

        CronTrigger trigger = new CronTrigger("trigger1", null, "myJob",
                                                null,scheduleFromDatabase );

        trigger.StartTimeUtc = DateTime.UtcNow;
        trigger.Name = "myTrigger";
        sched.ScheduleJob(jobDetail, trigger); 
    }

public class HelloJob:IJob
{

    public void Execute(JobExecutionContext context)
    {
        Console.WriteLine(DateTime.Now.ToString());
        //Call here your method!
    }
}

这可能是有用的:

Quartz.NET服务器文档

这篇关于如何设置Quartz.NET调度电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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