zoukankan      html  css  js  c++  java
  • 利用Cache,asp.net 简单实现定时执行任务

    利用Cache,让asp.net 简单实现定时执行任务
    代码
    private static CacheItemRemovedCallback OnCacheRemove = null;

    protected void Application_Start(object sender, EventArgs e)
    {
        AddTask(
    "DoStuff"60);
    }

    private void AddTask(string name, int seconds)
    {
        OnCacheRemove 
    = new CacheItemRemovedCallback(CacheItemRemoved);
        HttpRuntime.Cache.Insert(name, seconds, 
    null,
            DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration,
            CacheItemPriority.NotRemovable, OnCacheRemove);
    }

    public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
    {
        
    // do stuff here if it matches our taskname, like WebRequest
        
    // re-add our task so it recurs
        AddTask(k, Convert.ToInt32(v));
    }


  • 相关阅读:
    为zabbix穿上一件漂亮的外衣
    CentOS7 Ceph分布式集群部署
    SSH 免秘钥登录
    zabbix监控Tomcat/JVM 实例性能
    zabbix 监控 IPMI
    2装饰者模式
    1代理模式
    3单例模式
    2抽象工厂模式
    1工厂模式
  • 原文地址:https://www.cnblogs.com/jintan/p/1746135.html
Copyright © 2011-2022 走看看