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?
For better knowledge sharing:
There are two suggestions:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With