I am trying to follow http://weblogs.asp.net/scottgu/auto-start-asp-net-applications-vs-2010-and-net-4-0-series to implement some start up process in my asp.net application.
As of now we have a quartz.net scheduler registered in ASP.Net application_start method like below and running.
public static class QuartzHelper
{
public static void RunJob()
{
ISchedulerFactory schedFact = new StdSchedulerFactory();
IScheduler sched = schedFact.GetScheduler();
sched.Start();
IJobDetail job = JobBuilder.Create<SendDailyMorningSMSJob>()
.WithIdentity("Auto_DailyMorning8AM", "AutoSMS")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("SMS_Trigger", "AutoSMS")
.WithSchedule(CronScheduleBuilder
.DailyAtHourAndMinute(08,00)
.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time")))
.Build();
sched.ScheduleJob(job, trigger);
}
}
Then
protected void Application_Start()
{
QuartzHelper.RunJob();
}
The problem is, it is stopped running when IIS is recycling application pool. To make it work I tried to follow this approach.
public class PreWarmUp : IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
QuartzHelper.RunJob();
}
}
In ApplicationHost.config
<serviceAutoStartProviders>
<add
name="MCVApplicationNamespace"
type="MCVApplicationNamespace.QuartzHelper, QuartzHelper" />
</serviceAutoStartProviders>
But I read in MSDN
This interface is intended primarily for use by WCF applications that are non-HTTP applications. ASP.NET developers who want to preload ASP.NET Web applications should use the simulated HTTP requests in IIS 7.0 combined with the Application_Start method in the Global.asax file.
Now confused, do I need to have same code in PreWarmUp class as well in Application_Start?