1

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
        }
    }
}
mantal
  • 1,093
  • 1
  • 20
  • 38
Glinkot
  • 2,924
  • 10
  • 42
  • 67

1 Answers1

5

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
  • 6,586
  • 25
  • 29
  • @MarkoLahma Thanks but as far as I know Quartz.NET is used in order not to use Win Service. So, if we should use Win Service, is there any need to use Quartz.net? Is there another solution on application side? If so, could you give an example for MVC application? – Jack Nov 08 '15 at 12:46
  • 1
    @Christof you *can* host Quartz inside ASP.NET application but it has its pitfalls as noted. You *should* host Quartz.NET preferably inside a windows service and you also can have management front end using ASP.NET MVC etc which does not run the jobs, just manages the schedules and jobs. – Marko Lahma Nov 08 '15 at 15:23
  • 1
    Thanks for reply. I published the application on IIS Server and I think the best option for me to use Windows Service. So, could you please clarify me what changes should I made? I have an MVC5 Web Application and no idea how to trig the application or Quartz job weekly? I know the Windows Scheduler settings, I just need the other settings that I should do on application, quartz and windows side. – Jack Nov 09 '15 at 08:11