简体   繁体   English

Windows Server 2008 R2中未运行quartz.net作业

[英]quartz.net job not running in windows server 2008 R2

I created a windows service in c#.net, it uses quartz.net to do a job every hour. 我在c#.net中创建了一个Windows服务,它使用quartz.net每小时执行一次工作。 it works locally and doesn't have any problem. 它在本地工作,没有任何问题。 but when I installed it on server 2008 R2, it doesn't work. 但是,当我将其安装在服务器2008 R2上时,它不起作用。 it starts and no error. 它启动并且没有错误。 I used event log and I undrestood class JobScheduler works but jobs don't fire. 我使用了事件日志,但我的Unrestood类JobScheduler可以正常工作,但作业不会触发。 please help me. 请帮我。

     public class JobScheduler
{
    public static void Start()
    {
        try
        {
            ISchedulerFactory schedFact = new StdSchedulerFactory();
            IScheduler scheduler = schedFact.GetScheduler();
            scheduler.Start();
            IJobDetail job = JobBuilder.Create<CheckJob>().WithIdentity("MyJob", "group1").Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("myTrigger", "group1").StartNow().WithSimpleSchedule(s => s.WithIntervalInHours(1).RepeatForever()).Build();



            scheduler.ScheduleJob(job, trigger);
            EventLogging.Log("jobscheduling ok");


        }
        catch (Exception ex)
        {
            EventLogging.Log("jobscheduler:"+ex.Message);

        }
    }
}

In my experience with quartz, you can check a free points, 根据我使用石英的经验,您可以查看免费积分,

  1. Inspect the exe property and ensure it is not blocked 检查exe属性并确保它未被阻止

  2. Check for the proper connection string 检查正确的连接字符串

  3. Check if the required files are in correct path 检查所需文件是否在正确的路径中

  4. Try to write logs / enable logging to see what's going wrong 尝试编写日志/启用日志记录以查看发生了什么问题

You have a variable scope issue, because you are not keeping a reference to the scheduler outside of the Start method. 您有一个可变范围问题,因为您没有在Start方法之外保留对调度程序的引用。 In order for the scheduler to keep running after the Start method finishes running, the scheduler variable needs to be defined as a static variable, and not as a method variable. 为了使调度程序在Start方法完成运行后继续运行,需要将调度程序变量定义为静态变量,而不是方法变量。

You can use the quartz.server that comes with the package download. 您可以使用软件包下载随附的quartz.server。

https://github.com/quartznet/quartznet https://github.com/quartznet/quartznet

Once you feel comfortable with the framework - then create your own. 对框架感到满意后,请创建自己的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM