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过滤器Filter
			
过滤器 一. 简介 过滤器一般用于设置字符编码.登录验证.权限验证.敏感词过滤等,减少了代码的冗余,便于代码的复用,但是不一定是每个servlet都必须使用过滤器的. 二. 过滤器的工作流程 图片来源 ...
 - dict字典的一些优势和劣势
			
01. 键必须是可散列的一个可散列的对象必须满足以下要求. (1) 支持 hash() 函数,并且通过 __hash__() 方法所得到的散列值是不变的. (2) 支持通过 __eq__() 方法来检 ...
 - UVA11922 Permutation Transformer
			
思路 直接使用FHQ Treap维护即可 代码 #include <cstdio> #include <cstring> #include <algorithm> ...
 - 牛客OI周赛9-提高组题目记录
			
牛客OI周赛9-提高组题目记录 昨天晚上做了这一套比赛,觉得题目质量挺高,而且有一些非常有趣而且非常清奇的脑回路在里边,于是记录在此. T1: 扫雷 题目链接 设 \(f_i\) 表示扫到第 \(i\ ...
 - 《Java8实战》读书笔记
			
个人感悟: 1.lambda表达式,补充了JAVA在面向对象之外,面向过程的一面.在写面向过程代码的时候更方面了,甚至可以利用代码来做类似数学公式的运算(P64) 2.流,对集合的操作,就像用SQL对 ...
 - 算法笔记--Splay && Link-Cut-Tree
			
Splay 参考:https://tiger0132.blog.luogu.org/slay-notes 普通模板: ; ], val[N], cnt[N], fa[N], sz[N], lazy[N ...
 - 小程序分享进入H5动态网页
			
在要分享的界面加上这段代码 onShareAppMessage: function (options) { var that = this; // var return_url = that.data ...
 - SVN-Failed to run the WC DB work queue associated with
			
解决方法:清空svn的队列 1.下载sqlite3.exe 2.找到你项目的.svn文件,查看是否存在wc.db 3.将sqlite3.exe放到.svn的同级目录 4.启动cmd执行sqlite3 ...
 - numpy 数组索引数组
			
在numpy中,数组除了可以被整数索引,还可以被数组索引. a[b]就是已数组b的元素为索引,读取数组a的值. 当被索引数组a是一维数组,b是一维或则多维数组时,结果维度维度与索引数组b相同. a = ...
 - The innodb_system data file 'ibdata1' must be writable
			
在安装MySQL的时候报的错,我理解的这个错是因为有个文件是Innodb需要在安装MySQL(或者创建数据库的时候)的时候需要写入这个文件,但是他现在没有写的权限. 日志中的错误是: 5.7版本以前是 ...