views:

250

answers:

1

Hi. I have a timed quartz.net job working fine on my dev machine, but once deployed to a remote server it is not triggering. I believe the job is scheduled ok, because if I postback, it tells me the job already exists (I normally check for postback however). The email code definitely works, as the 'button1_click' event sends emails successfully.

I understand I have full or medium trust on the remove server. My host says they don't apply restrictions that they know of which would affect it. Any other things I need to do to get it running?

        using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Quartz;
    using Quartz.Impl;
    using Quartz.Core;
    using Aspose.Network.Mail;
    using Aspose.Network;
    using Aspose.Network.Mime;
    using System.Text;

    namespace QuartzTestASP
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    ISchedulerFactory schedFact = new StdSchedulerFactory();
                    IScheduler sched = schedFact.GetScheduler();
                    JobDetail jobDetail = new JobDetail("testJob2", null, typeof(testJob));
                    //Trigger trigger = TriggerUtils.MakeMinutelyTrigger(1, 3);
                    Trigger trigger = TriggerUtils.MakeSecondlyTrigger(10, 5);
                    trigger.StartTimeUtc = DateTime.UtcNow;
                    trigger.Name = "TriggertheTest";
                    sched.Start();
                    sched.ScheduleJob(jobDetail, trigger);
                }

            }

            protected void Button1_Click1(object sender, EventArgs e)
            {
                myutil.sendEmail();
            }
        }

        class testJob : IStatefulJob
        {
            public testJob() { }

            public void Execute(JobExecutionContext context)
            {
                myutil.sendEmail();
            }

        }

        public static class myutil
        {
            public static void sendEmail()
            {
    // tested code lives here and works fine when called from elsewhere
            }


        }
    }
+1  A: 

The scheduler factory should be global to your application. In other words, declare it in Global.asax or similar that effectively gives you a global instance to operate with. You should start the scheduler in your application start if running ASP.NET.

Beware thought. ASP.NET recycles its processes which effective causes shutdown of scheduler (no jobs will run) until next next request comes in to web server to start the scheduler again. The recommended way is to have a windows service for running Quartz.NET jobs.

Marko Lahma
Many thanks. You're right, the scoping was the issue...!
Glinkot