How to detect if the current application pool is winding up in IIS7.5 and Asp.Net 3.5+

前端 未结 4 1588
清酒与你
清酒与你 2020-12-08 05:21

Well - exactly as the question subject states - any ideas on how you might do this?

I\'ve been looking over the objects in System.Web.Hosting but nothing is standing

4条回答
  •  忘掉有多难
    2020-12-08 05:51

    Adding the actual code to do this:

    public class RecycleWatcher : IRegisteredObject
    {
        public static bool IsRecycling { get; private set; }
    
        public void Register()
        {
            HostingEnvironment.RegisterObject(this);
        }
        public void Stop(bool immediate)
        {
            IsRecycling = true;
        }
    }
    

    Then enable it by running

    new RecycleWatcher().Register();
    

    After that just check that property for IsRecycling to know if you are recyling or not.

    if (RecycleWatcher.IsRecycling) DoSomething();
    

提交回复
热议问题