C# Global定时执行Global文件aTimer处理
public class Global : System.Web.HttpApplication
{
private static event Action eventActions;
/// <summary>
/// 当前正在运行的异步线程池
/// </summary>
private static Dictionary<string, IAsyncResult> diyAsync = new Dictionary<string, IAsyncResult>();
protected void Application_Start(object sender, EventArgs e)
{
eventActions += MyClass.Writer;//任务(可以处理多个方法)
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = ;
aTimer.Enabled = true;
}
/// <summary>
/// 定时执行任务
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
foreach (Action action in eventActions.GetInvocationList())
{
try
{
if (diyAsync.Any(p => p.Key == action.Method.Name) && !diyAsync[action.Method.Name].IsCompleted)
continue;
diyAsync[action.Method.Name] = action.BeginInvoke(null, null);
}
catch (Exception ex)
{
//任务执行出错
}
}
}
protected void Session_Start(object sender, EventArgs e)
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
} protected void Application_BeginRequest(object sender, EventArgs e)
{
string name=System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
} protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
string name=System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
} protected void Application_Error(object sender, EventArgs e)
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
WH_WriteLog.WriteLog(e.ToString());
} protected void Session_End(object sender, EventArgs e)
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
} protected void Application_End(object sender, EventArgs e)
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
}
} public class MyClass
{
public static void Writer()
{
string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
WH_WriteLog.WriteLog(name);
}
}
C# Global定时执行Global文件aTimer处理的更多相关文章
- windows上定时执行php文件
<?php $fp = fopen("E:/wwwroot/test/plan.txt", "w+"); fwrite($fp, date("Y ...
- Asp.net Global 定时执行
在复杂的业务应用程序中,有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行,比如定时备份或同步数据库,定时发送电子邮件,定期处理用户状态信息,支付系统中定期同步异常账单等等,我们称之 ...
- Windows Server 2008通过计划任务定时执行bat文件
前段时间在Windows Server 2008安装了一套基于MySQL数据库的软件,处于数据安全的考虑,希望每天能够自动进行数据库备份.我在别人脚本的基础上自己写了一个数据库备份的bat脚本,双击该 ...
- 解决Windows Server 2008R2通过计划任务定时执行bat文件,显示成功但实际未执行
前段时间在Windows Server 2008安装了一套基于MySQL数据库的软件,处于数据安全的考虑,希望每天能够自动进行数据库备份.我在别人脚本的基础上自己写了一个数据库备份的bat脚本,双击该 ...
- OSX系统添加定时任务 Linux crontab命令 定时执行py 文件 任务
#输出日志 #将日志输入到2.log文件中无论错误还是正确02 15 * * * . ~/xad/pyenv/xadserver/bin/activate && cd /root/xa ...
- win2008通过计划任务定时执行bat文件
前段时间在Windows Server 2008安装了一套基于MySQL数据库的软件,处于数据安全的考虑,希望每天能够自动进行数据库备份.我在别人脚本的基础上自己写了一个数据库备份的bat脚本,双击该 ...
- 使用crontab定时执行python文件问题追根溯源
使用crontab执行定时任务不是第一次用,昨天下午设置几个任务,yy里面已存在的任务,修改指定python环境和执行文件路径后,死活到点不执行. 任务设置如下: 15 16 * * * /root/ ...
- liunx 定时执行 php文件
which php 寻找php路径
- Windows通过计划任务定时执行bat文件
第一步 第二步 第三步 第四步 第五步 第六步
随机推荐
- Android版本28使用http请求
Android版本28使用http请求报错not permitted by network security policy android模拟器调试登录的时候报错 CLEARTEXT communic ...
- JS之clientX,clientY,screenX,screenY,offsetX,offsetY区别
首先需要知道clientX,clientY,screenX,screenY,offsetX,offsetY 是鼠标事件对象下的几个属性. 之前也一直对这些属性搞的稀里糊涂,看文档上说的也是不太理解,反 ...
- systemd的新特性及unit常见类型分析与awk用法示列
简述systemd的新特性及unit常见类型分析,能够实现编译安装的如nginx\apache实现通过systemd来管理 系统引导的新特性 系统引导时实现服务启动: 按需激活进程: 系统状态快照: ...
- poi 工具类
<!--POI--> <dependency> <groupId>org.apache.poi</groupId> <artifactId> ...
- 天融信防火墙NGFW4000,无法进入web管理和community属性查看
1.system config save //配置保存 2.system config reset //清除配置(恢复出厂设置) 3.pf service add name webui area a ...
- A*搜索详解(2)——再战觐天宝匣
书接上文.在坦克寻径的,tank_way中,A*算法每一步搜索都是选择F值最小的节点,步步为营,使得寻径的结果是最优解.在这个过程中,查找最小F值的算法复杂度是O(n),这对于小地图没什么问题,但是对 ...
- sql语句实例练习
1.最晚入职员工查询 select * from employees where hire_date = (select max(hire_date) from employees) 2.倒数第三 ...
- Windows和Office激活工具Kmsauto Net
对于微软操作系统和OFFICE的激活,以前笔者用过 ”HEU_KMS_Activator_v11.2.0” ,不过这个工具速度相对比较慢.今天给大家推荐一个新的激活工具:KmsautoNet . 很简 ...
- php使用select语句查询数据信息
<html> <head> <title>Finding User</title> </head> <body> <h2& ...
- django中form页面刷新后自动提交的解决方案
如果一个页面包含了form,同时这个form中的提交按钮是type=submit的input的时候,你刷新该页面,就会有弹窗提示是否重新提交表单,这个特性不胜其烦,常见解决方法有两个: 第一种是前端的 ...