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才明白入口,所以现在 ...
随机推荐
- luoguP1919 A*B Problem升级版 ntt
luoguP1919 A*B Problem升级版 链接 luogu 思路 ntt模板题 代码 #include <bits/stdc++.h> #define ll long long ...
- 【ASP.NET】 HttpContext.Current.User.Identity.Name 返回值为空
问题起因 在做项目的时候,我使用HttpContext.Current.User.Identity.Name来获取Web应用程序正在使用时的用户名. 在开发过程中,我使用了我的本地iis,启用了集成的 ...
- 【HNOI 2018】转盘
Problem Description 一次小 \(G\) 和小 \(H\) 原本准备去聚餐,但由于太麻烦了于是题面简化如下: 一个转盘上有摆成一圈的 \(n\) 个物品(编号 \(1\) 至 \(n ...
- 做数据挖掘,就算发 20 几分的 CNS 子刊,也是垃圾!?--转载
关于数据挖掘发表文章,我们知道很多人是看不上.瞧不起.嗤之以鼻的.大抵是因为这些人平时只发 CNS 主刊,所以才认为通过数据挖掘这种用「别人的数据」或者叫「干实验」来发文章是“「垃圾」,没有什么价值. ...
- RN截图并且下载问题
神奇的BUG一大堆. 需求-->截图并且下载图片 实现: import ViewShot from "react-native-view-shot"; CameraRoll ...
- Python自动发送邮件提示:smtplib.SMTPServerDisconnected: please run connect() first
参考:http://blog.csdn.net/leven_change/article/details/66976695
- 学习笔记70—Photoshop画齿轮
具体步骤如下: 1)选择多边形工具: 2)设置齿轮个数及颜色相应参数: 3)画出模型: 4)找到上图模型的中心 (借助:ctrl + T),选择椭圆工具,并 长按Shift+Alt, 画出圆: 5) ...
- [大数据面试题]hadoop核心知识点
* 面试答案为LZ所写,如需转载请注明出处,谢谢. * 这里不涉及HiveSQL和HBase操作的笔试题,这些东西另有总结. 1.MR意义. MR是一个用于处理大数据的分布式离线计算框架,它采用”分而 ...
- 【Code Tools】Java微基准测试工具JMH之入门篇
一.JMH是什么 JMH是一个Java工具,用于构建.运行和分析用Java和其他语言编写的以JVM为目标的 nano/micro/milli/macro 基准测试. 二.基本注意事项 1)运行JMH基 ...
- textarea跟随内容自动伸缩高度实现方案
监听input事件,然后将textarea的style.height设置为最低高度(19px),进而获取到元素的scrollHeight,然后将scroolHeight设置为style.height