Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
668 views
in Technique[技术] by (71.8m points)

c# - IIS app pool recycle + quartz scheduling

I'm running a web app on IIS 7.5 and it needs to recycle occasionally (otherwise memory usage gets out of handing, something i'm looking into!).

When it recycles, it is effectively not running until another request comes in, which quartz is not going to run.

Is there any way to have IIS automatically bring up 1 work process immediately after recycling the app pool to ensure quartz is always online?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes!

http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx details it quite nicely, basically you need to:

  1. Edit C:WindowsSystem32inetsrvconfigapplicationHost.config to include:

    <applicationPools> 
        <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" /> 
    </applicationPools>
    
  2. Declare what should be run as the "warm-up" for your site

    <sites> 
        <site name="MySite" id="1"> 
            <application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />
        </site> 
    </sites>
    <serviceAutoStartProviders> 
        <add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" /> 
    </serviceAutoStartProviders> 
    
  3. Configure your application with whatever "warm-up" logic you would like:

    public class PreWarmCache : System.Web.Hosting.IProcessHostPreloadClient {
        public void Preload(string[] parameters) { 
            // Perform initialization and cache loading logic here... 
        } 
    } 
    

Note: If all you need is for the w3wp.exe process to be present I believe only step 1 is necessary. If you also need other items (like certain things to be loaded into memory) then step 2 and 3 would also be used.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...