C# Global.asax.cs 定时任务
定时执行更新Redis缓存操作
protected void Application_Start(object sender, EventArgs e)
{
Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = ; //执行间隔时间,单位为毫秒; 这里实际间隔为1小时
timer.Start();
timer.Elapsed += new System.Timers.ElapsedEventHandler(OrgCacheInterval);
} /// <summary>
/// 定时检测组织机构缓存是否需要更新
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
public void OrgCacheInterval(object source, ElapsedEventArgs e)
{
SystemService ser = new SystemService();
ser.OrgCacheInterval();
}
/// <summary>
/// 组织机构缓存定时更新
/// </summary>
public void OrgCacheInterval()
{
//不存在组织机构缓存或者时间戳时,更新
if (!RedisCacheHelper.Exists("OrgList") || !RedisCacheHelper.Exists("OrgList:Time"))
{
UpdateAllOrgCache();
}
//存在时间戳时判断时间是否一致,不一致时更新
else
{
//缓存时间戳
string cacheTime = RedisCacheHelper.Get<string>("OrgList:Time");
//数据库更新缓存时间
string modifyTime = OrgDb.GetKeyLastModifyTime("OrgList", "");
//时间戳标记不一致时更新
if (cacheTime != modifyTime)
{
UpdateAllOrgCache();
}
}
}
/// <summary>
/// 获取键值更新时间
/// </summary>
/// <param name="db_key"></param>
/// <param name="lang_type"></param>
/// <returns></returns>
public string GetKeyLastModifyTime(string db_key, string lang_type)
{
string time = string.Empty;
try
{
string sql = string.Format(@"select * from sys_dbcache_time t where 1=1 and t.db_key='{0}' ", db_key);
if (!string.IsNullOrEmpty(lang_type))
{
sql += string.Format(@" and t.lang_type='{0}' ", lang_type);
}
DataTable dt = OdpOracleHelper.Query(sql).Tables[];
if (dt != null && dt.Rows.Count > )
{
time = Convert.ToDateTime(dt.Rows[]["op_modify_time"]).ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
string _time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string insertSql = string.Format(@"insert into sys_dbcache_time(db_key,lang_type,op_modify_time)
values('{0}','{1}',to_date('{2}','yyyy-MM-dd HH24:MI:SS'))", db_key, lang_type, _time);
OdpOracleHelper.ExecuteSql(insertSql);
time = _time;
}
}
catch (Exception ex)
{
throw ex;
}
return time;
}
C# Global.asax.cs 定时任务的更多相关文章
- Where is the Global.asax.cs file
I am using VS 2008. I have created a new Asp.net web site project from File->New->Website-> ...
- ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global" Language="C#" %>
ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global&q ...
- <%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Language="C#" %>
<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.MvcApplication" Lan ...
- Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer
x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer(& ...
- Global.asax.cs介绍
转载 http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...
- Global.asax.cs中相关方法
protected void Session_Start(object sender, EventArgs e) { #if DEBUG //debug 登陆默认设置 #endif } protect ...
- .Global.asax.cs中的方法的含义
Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...
- asp.net(C#)网站发布后 Global.asax 里 Application_Error 不执行的问题
现象 在 Global.asax 用 Application_Error 捕捉了http的404,500等错误,在本机测试正常,发布后无效,几经周折终于解决了... 程序是这样设计的 Applicat ...
- ASP.NET Global.asax详解
最近在研究bbsmax的代码,但是一直不知道入口在哪里,然后就对各个文件分析了,然后终于在对global.asax文件查看的时候看到Application_BeginRequest才明白入口,所以现在 ...
随机推荐
- Java多线程的创建与简单使用
一.线程的基本概念 什么是线程:Thread 进程内部的一个执行单元,它是程序中一个单一的顺序控制流程. 线程又被称为轻量级进程(lightweight process) 如果在一个进程中同时运行了多 ...
- IIC为什么要配置为开漏输出呢?
开漏输出只能输出低电平,类似于三极管的集电极,要输出高电平需要上拉电阻才能输出 当集电极接上拉电阻后,(1)基极为高电平,三极管导通,集电极的电位就会被拉低: (2)基极为低电平,三极管不导通,集电极 ...
- 15_Raid及mdadm命令 _LVM
磁盘管理: 机械式硬盘: U盘,光盘,软盘,硬件,磁带 ln [ -s -v ] SRC DEST 硬链接: 1.只能对文件创建,不能应用于目录 2.不能跨文件系统 ...
- Jenkins之定时构建
参考文章:https://blog.csdn.net/ZZY1078689276/article/details/77520441 第一个*表示分钟,取值0~59 第二个*表示小时,取值0~23 第三 ...
- day24
## 复习 1.类对象属性的查找顺序: 先找自身再找类1)类的名称空间:直接写在类中2) 对象的名称空间:写在__init__方法中,通过self.属性形成名称空间中的名字3) 类的方法:在类中用@c ...
- Docker Swarm集群中部署Traefik负载均衡器
一.创建单节点的Docker Swarm集群 docker swarm init 二.在Swarm集群中创建一个网络 docker network create --driver=overlay tr ...
- jmeter简单得压力测试
Jmeter教程 简单的压力测试 Jmeter是一个非常好用的压力测试工具. Jmeter用来做轻量级的压力测试,非常合适,只需要十几分钟,就能把压力测试需要的脚本写好. 阅读目录 什么是压力测试 ...
- selenium、UA池、ip池、scrapy-redis的综合应用案例
案例: 网易新闻的爬取: https://news.163.com/ 爬取的内容为一下4大板块中的新闻内容 爬取: 特点: 动态加载数据 ,用 selenium 爬虫 1. 创建项目 scrapy ...
- js vue 在页面中将摄像头放在一个标签里展示,(模仿手机拍照功能)
1.HTML <video id="video" autoplay class="fileImg"></video> <canva ...
- 重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
出现报错: Warning: World-writable config file '/etc/my.cnf' is ignored // 该文件权限过高ERROR 1045 (28000): Acc ...