zoukankan      html  css  js  c++  java
  • IIS应用程序池自动回收问题的有效解决办法

    问题:Timer不能持续执行,如果长时间没有访问,就会被IIs自动回收。造成一些定时作业无法完成。

    解决方式1:改用windows服务或是winform方式

    解决方式2:在Application_End事件模拟加载网站页面,唤醒要被回收的资源

    private const string DummyPageUrl = "http://localhost/Index.aspx";//可访问的页面
    private const string DummyCacheItemKey = "Du";

    // 注册一缓存条目在5分钟内到期,到期后触发的调事件
    private void RegisterCacheEntry()
    {
      if (null != HttpContext.Current.Cache[DummyCacheItemKey]) return;
      HttpContext.Current.Cache.Add(DummyCacheItemKey, "Test", null, DateTime.MaxValue,
      TimeSpan.FromMinutes(5), CacheItemPriority.NotRemovable,
      new CacheItemRemovedCallback(CacheItemRemovedCallback));
    }
    // 缓存项过期时程序模拟点击页面,阻止应用程序结束
    public void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason)
    {
      HitPage();
    }
    // 模拟点击网站网页
    private void HitPage()
    {
      System.Net.WebClient client = new System.Net.WebClient();
      client.DownloadData(DummyPageUrl);
    }
    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
      if (HttpContext.Current.Request.Url.ToString() == DummyPageUrl)
      {
        RegisterCacheEntry();
      }
    }
    protected void Application_Start(object sender, EventArgs e)
    {
      RegisterCacheEntry();
    }

  • 相关阅读:
    Vue的watch监听事件
    Vue路由-命名视图实现经典布局
    Vue中使用children实现路由的嵌套
    Vue中router两种传参方式
    mysql 压缩备份 压缩还原 命令
    【转】SVN branches trunk 合并 讲解
    svn 更新提交文件冲突
    mysql 导出表数据表结构
    利用jenkins打造通过自定义参数更新svn 指定文件任务
    centos 7 安装jira 破解
  • 原文地址:https://www.cnblogs.com/erictanghu/p/3554516.html
Copyright © 2011-2022 走看看