Quartz and ASP.NET

32 views
Skip to first unread message

jumbojs

unread,
Dec 30, 2009, 10:44:21 AM12/30/09
to Quartz.NET
Hello,

New to Quartz but it seems powerful and I want to use it in my asp.net
applications. So far I've added this to my Application_Start and the
class and I'm trying to have it run every two minutes but nothing is
happening. Figured I missed something.

protected void Application_Start(object sender, EventArgs e)
{
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler
IScheduler sched = schedFact.GetScheduler();


// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof
(IMAutoJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeMinutelyTrigger(2);
// start on the next even hour
trigger.StartTimeUtc = TriggerUtils.GetEvenHourDate
(DateTime.UtcNow);
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger);
sched.Start();
}

And I've added this class to the App_Code Folder

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Quartz;

/// <summary>
/// Summary description for IMAutoJob
/// </summary>
public class IMAutoJob : IJob
{
public IMAutoJob()
{

}

#region IJob Members

public void Execute(JobExecutionContext context)
{
IM.RunUpdate();
}

#endregion
}

Vadivel Kumar

unread,
Dec 30, 2009, 3:07:27 PM12/30/09
to quar...@googlegroups.com
You should start sched.Start in a different thread. I think since it is blocking call, your Application_Start will not get finish over.


--

You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To post to this group, send email to quar...@googlegroups.com.
To unsubscribe from this group, send email to quartznet+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/quartznet?hl=en.





--
Best Regards,
Vadi

Marko Lahma

unread,
Dec 30, 2009, 4:16:45 PM12/30/09
to quar...@googlegroups.com
You should at least keep an instance of the scheduler factory around.
Now it's just visible until the end of application start method and
after that it'll be presumably eligible to garbage collection. So what
if you try with having a "private static ISchedulerFactory schedFact"
as a field?

And again I would advice to have a different process to handle job
scheduling (Windows services).

-Marko

Swami Iyer

unread,
Dec 30, 2009, 5:32:30 PM12/30/09
to quar...@googlegroups.com
IMHO, It is a bad idea to do this ASP.NET code. Because you have to
make sure that the IIS lifecycle does not destroy this application
from the app pool when it is idle. (not getting http request).

Having said that what marko points out is the issue. The scheduler
instance is getting GC.

--
Thanks,
Swami

jumbojs

unread,
Dec 30, 2009, 6:43:51 PM12/30/09
to Quartz.NET
I'm sure it's not the best idea to use this in ASP.NET but I have to
have this working fast and I'm executing a method that belongs inside
a dll inside my web app. I have no idea how to get this to work using
a windows service but I'll look at that later. I'll try adding the
ISchedulerFactory as a static field and see if that works... thanks.

On Dec 30, 3:16 pm, Marko Lahma <marko.la...@gmail.com> wrote:
> You should at least keep an instance of the scheduler factory around.
> Now it's just visible until the end of application start method and
> after that it'll be presumably eligible to garbage collection. So what
> if you try with having a "private static ISchedulerFactory schedFact"
> as a field?
>
> And again I would advice to have a different process to handle job
> scheduling (Windows services).
>
> -Marko
>

jumbojs

unread,
Dec 30, 2009, 6:55:02 PM12/30/09
to Quartz.NET
I've added this

private static ISchedulerFactory schedFact = new StdSchedulerFactory
();


protected void Application_Start(object sender, EventArgs e)
{
// construct a scheduler factory

//ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler
IScheduler sched = schedFact.GetScheduler();


// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof
(IMAutoJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeMinutelyTrigger(2);
// start on the next even hour
trigger.StartTimeUtc = TriggerUtils.GetEvenHourDate
(DateTime.UtcNow);
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger);
sched.Start();
}

And still nothing is happening.

On Dec 30, 4:32 pm, Swami Iyer <onlyone.swamii...@gmail.com> wrote:
> IMHO, It is a bad idea to do this ASP.NET code. Because you have to
> make sure that the IIS lifecycle does not destroy this application
> from the app pool when it is idle. (not getting http request).
>
> Having said that what marko points out is the issue. The scheduler
> instance is getting GC.
>
>
>
> On Wed, Dec 30, 2009 at 4:16 PM, Marko Lahma <marko.la...@gmail.com> wrote:
> > You should at least keep an instance of the scheduler factory around.
> > Now it's just visible until the end of application start method and
> > after that it'll be presumably eligible to garbage collection. So what
> > if you try with having a "private static ISchedulerFactory schedFact"
> > as a field?
>
> > And again I would advice to have a different process to handle job
> > scheduling (Windows services).
>
> > -Marko
>

> >> For more options, visit this group athttp://groups.google.com/group/quartznet?hl=en.

jumbojs

unread,
Dec 30, 2009, 7:01:11 PM12/30/09
to Quartz.NET
I saw this .GetEvenHourDate in my code and I think that's why it
wasn't running. I'm trying to get this to run every two minutes.
Reply all
Reply to author
Forward
0 new messages