Question

I use quartz in my asp website, i initialize the scheduler in application_start method and shutdown in application_end method ,my trigger will fire everyday but I found that my scheduler will automatically shutdown if there are not request for a while ,so my background works will not triggered,are there any better way to keep the scheduler life long and only shutdown when the server stopped?

OTHER TIPS

In general, if you need reliable scheduling, you should not do it within a web site.

As you've found, the worker process will be shut down after a period of time. Even if you force the worker process to run all the time, there are conditions that may cause it to terminate as well. It's just not a good idea.

Instead, you should write a Windows Service and run quartz.net in that.

If you cannot install services (say you're in a shared hosting environment), then your options are more limited.

There is an IIS configuration that allows worker processes to stay on all the time. I found this setting through another SO answer link.

Edit C:\Windows\System32\inetsrv\config\applicationHost.config to include:

<applicationPools> 
    <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" /> 
</applicationPools>

Scott Guthrie (Microsoft Product Manager for .NET) has answerered a question directly related to the OP's question (link).

@Dominic Pettifer,

If I set startMode="AlwaysRunning" does this mean the web app will 'never' shut down and will always be kept running, even with no traffic hitting the site for a long period (unless of course it's manually shut down, or server is switched off/crashes etc.)? The reason I ask is because I like to run background threads/services on the IIS ASPNET worker process instead of using Windows Services (we deal with clients with lots of security restrictions on their servers which makes running a Windows Service difficalt or impossible). Normally I have to devise something that hits the website periodically to keep the ASPNET worker process alive and stop it from shutting down.

This should mean that the application and worker process is always running - so I think that does indeed handle your scenario well for you.

Hope this helps,

Scott

I wondered the same thing. Ultimately, whilst I agree with the general consensus, I wanted to see how it could be done, because I've been in a similar situation myself, where Windows Services were not available to me.

All I did was create a new job which, when executed sends a HTTP request to the application itself. For me, I pointed it at a page which simply contained @Datetime.Now.ToString().

The action of sending a HTTP request to itself should be enough to keep the scheduler (and parent worker process) alive.

It does not however stop the application from being stopped/recycled without warning. If you wanted a way to handle that, then you'd likely need more than one site running which pings both itself and the other site. This way, if one site goes down, the other can hit it (assuming it's started) to bring it back.

A much simpler way to is use a quality assurance checker. Using the tool Zapix I was able to schedule my website to be quality checked every 20 minutes. Zapix simply visited the site and received and http response. By using Zapix, it mimicked the functionality of manually visiting the website to trigger the emails. That way, the Application Pool threads are constantly woke.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top