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文件
第一步 第二步 第三步 第四步 第五步 第六步
随机推荐
- css3实现小程序的动画
<view class="biground" > <block wx:for="{{Namelist}}" wx:key=" ...
- Codeforces 1105B:Zuhair and Strings(字符串水题)
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...
- python中的Matplot库和Gdal库绘制富士山三维地形图-参考了虾神的喜马拉雅山
首先请大家读一下面这篇文章了解什么是Gdal http://blog.csdn.net/grllery/article/details/77822595 剩下的我要公布绘制富士山的代码了,虽然基本co ...
- .NET数据采集
public string GetHttpData(string Url) { string sException = null; string sRslt = null; WebResponse o ...
- [ Codeforces Round #554 (Div. 2) C]
C. Neko does Maths time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Javascript 3.3 编写DOM脚本的四个基本方法
id属性的用途是给某个元素加上独一无二的标识符,搭配"#"使用 class搭配"."使用 getElementById()方法:方法名称的大小写不能写错,方法将 ...
- vue.js学习第一天,了解vue.js
vue.js是一个前端框架,他与jquery不同,jquery是一个js库,而vue.js是js的前端框架. vue.js对我们前端页面入侵比较大,而jquery则不然.那我们还为什么要使用vue.j ...
- 学习笔记DL005:线性相关、生成子空间,范数,特殊类型矩阵、向量
线性相关.生成子空间. 逆矩阵A⁽-1⁾存在,Ax=b 每个向量b恰好存在一个解.方程组,向量b某些值,可能不存在解,或者存在无限多个解.x.y是方程组的解,z=αx+(1-α),α取任意实数. A列 ...
- java基础(一):我对java的三个环境变量的简单理解和配置
首先说说java的三个环境变量:java_home,classpath,path java_home:jdk的安装路径[你一层一层点开安装路径,直到当前目录有一个bin目录,然后在地址栏里面右键单击复 ...
- python2和3的区别
一.默认编码 2:ascii 3:utf-8 二.数字 python3无long