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处理的更多相关文章

  1. windows上定时执行php文件

    <?php $fp = fopen("E:/wwwroot/test/plan.txt", "w+"); fwrite($fp, date("Y ...

  2. Asp.net Global 定时执行

    在复杂的业务应用程序中,有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行,比如定时备份或同步数据库,定时发送电子邮件,定期处理用户状态信息,支付系统中定期同步异常账单等等,我们称之 ...

  3. Windows Server 2008通过计划任务定时执行bat文件

    前段时间在Windows Server 2008安装了一套基于MySQL数据库的软件,处于数据安全的考虑,希望每天能够自动进行数据库备份.我在别人脚本的基础上自己写了一个数据库备份的bat脚本,双击该 ...

  4. 解决Windows Server 2008R2通过计划任务定时执行bat文件,显示成功但实际未执行

    前段时间在Windows Server 2008安装了一套基于MySQL数据库的软件,处于数据安全的考虑,希望每天能够自动进行数据库备份.我在别人脚本的基础上自己写了一个数据库备份的bat脚本,双击该 ...

  5. OSX系统添加定时任务 Linux crontab命令 定时执行py 文件 任务

    #输出日志 #将日志输入到2.log文件中无论错误还是正确02 15 * * * . ~/xad/pyenv/xadserver/bin/activate && cd /root/xa ...

  6. win2008通过计划任务定时执行bat文件

    前段时间在Windows Server 2008安装了一套基于MySQL数据库的软件,处于数据安全的考虑,希望每天能够自动进行数据库备份.我在别人脚本的基础上自己写了一个数据库备份的bat脚本,双击该 ...

  7. 使用crontab定时执行python文件问题追根溯源

    使用crontab执行定时任务不是第一次用,昨天下午设置几个任务,yy里面已存在的任务,修改指定python环境和执行文件路径后,死活到点不执行. 任务设置如下: 15 16 * * * /root/ ...

  8. liunx 定时执行 php文件

    which php    寻找php路径

  9. Windows通过计划任务定时执行bat文件

    第一步 第二步 第三步 第四步 第五步 第六步

随机推荐

  1. Request、Response

    Request Request对象在我们写爬虫发送请求的时候调用,参数如下: url: 就是需要请求的url callback: 指定该请求返回的Response由那个函数来处理. method: 请 ...

  2. Javascript 4.3 事件处理函数

    鼠标指针悬停在某个元素上时触发一个动作:onmouseover事件处理函数 鼠标指针离开某个元素时触发一个动作:onmouseout事件处理函数 点击某个链接时触发一个动作:onclick事件处理函数 ...

  3. About cookie

    1.cookie 是一种发送到客户浏览器的文本串句柄,并保存在客户机硬盘上,可以用来在某个WEB站点会话间持久的保持数据. 2.session其实指的就是访问者从到达某个特定主页到离开为止的那段时间. ...

  4. 巡风配置安装 –centOS6.5

    巡风是一款适用于企业内网的漏洞快速应急.巡航扫描系统,通过搜索功能可清晰的了解内部网络资产分布情况,并且可指定漏洞插件对搜索结果进行快速漏洞检测并输出结果报表. 其主体分为两部分:网络资产识别引擎,漏 ...

  5. Python基础:四、python的优缺点

    python是一门动态解释性的强类型语言 python的优点: 1. python的定位是"优雅"."明确"."简单" python程序看上 ...

  6. Sublime3安装及配置

    1.官网下载 2.安装后输入密钥 ----- BEGIN LICENSE -----sgbteamSingle User LicenseEA7E-11532598891CBB9 F1513E4F 1A ...

  7. centos7进单用户

    当重启linux系统,进入系统选择页面的时候,按e 在linux16那一行最后面添加 init=/bin/sh 按ctrl+c 挂载根分区,可读写 mount / -o rw, remount

  8. ubutu16.04 安装Tenda u12无线网卡驱动

    ubutu16.04 安装Tenda u12无线网卡驱动 一些问题: 1) Tenda u12 linux版本的驱动支持 kernel 2.6 到 4.4,而前系统内版本核为4.10,所以编译不过去啦 ...

  9. edgedb 基本试用

    环境准备 使用docker-compose 运行 docker-compose 文件 version: "3" services: db: image: edgedb/edgedb ...

  10. Vector Math for 3D Computer Graphics (Bradley Kjell 著)

    https://chortle.ccsu.edu/VectorLessons/index.html Chapter0 Points and Lines (已看) Chapter1 Vectors, P ...