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文件
第一步 第二步 第三步 第四步 第五步 第六步
随机推荐
- flask中注册验证码和分页
注册验证码.核心思路,替换注册页面的img标签的src属性. 1.准备好文件夹:captcha2.导包 from utils.captcha.captcha import captcha3.验证码生成 ...
- 通过sql查找指定字段存在哪些表中
select * from INFORMATION_SCHEMA.columns where COLUMN_NAME Like '%order_type%';
- 第二次Scrum冲刺——Life in CCSU
第二次Scrum冲刺——Life in CCSU 一. 第二次Scrum任务 继续上一次冲刺的内容,这次完成论坛部分. 二. 用户故事 用户输入账号.密码: 用户点击论坛部分: 系统显示帖子: 用户选 ...
- java-多线程(上)
###24.01_多线程(多线程的引入)(了解) * 1.什么是线程 * 线程是程序执行的一条路径, 一个进程中可以包含多条线程 * 多线程并发执行可以提高程序的效率, 可以同时完成多 ...
- c++输出小数
#include <stdio.h> printf("%.4lf",value); #include <iomanip> cout.setf(ios::sh ...
- day03 文件操作
目录 1.文件操作实例 2.文件常用操作 3.with模块操作文件 常用实例,把文件里面的内容读出来做成字典的形式在做成字列表展示. 1.精简版. lst = []f = open("fil ...
- Http数据协商
一.定义: 客户端发送给服务端请求的时候,声明拿到的数据格式以及相关的限制.服务端根据请求做出判断,返回相应的数据. 二.分类 1.请求 Accept : 想要的的数据类型 Accept-Encodi ...
- 0.5px border 实现方案
<div class='thin-border'></div> .thin-border { position: relative; width: 40px; height: ...
- java读取json文件进行解析,String转json对象
String jsonFilePath = "C:/a.json"; File file = new File(jsonFilePath ); String input = Fil ...
- CentOS7下安装Python3并保留Python2
1. 安装make编译指令的依赖环境 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel ...