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 = 200;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);}}

转载于:https://www.cnblogs.com/-hao/p/9944813.html

C# Global定时执行Global文件aTimer处理相关推荐

  1. ubuntu 定时执行php文件,Ubuntu crontab 定时执行php脚本文件

    什么是Cron和Crontab Unix和Linux系统的各个发行版本基本都支持Cron,Cron /Crontab允许我们在设定的时间自动执行或定时执行某个任务,如应用程序或脚本.更详细的概念和使用 ...

  2. linux 定时执行php文件

    工作需要 经常我们会定时执行php一个程序 满足业务需求 比如 :定时给用户进行邀请返利.定时进行用户消费排名更新.定时进行余额转账等等. 原来之前博客写过定时进行数据库和线上代码的备份. 现在记录哈 ...

  3. linux定时执行sh文件

    Linux定时任务调用sh文件 博客出处:http://www.cnblogs.com/413xiaol/p/6821740.html 1.编写sh文件 创建:vi test.sh 写入:date & ...

  4. Windows Server 2012计划任务定时执行bat文件

    推荐个人GItHub开源项目(iot-dc3)一个开源的.分布式的物联网(IOT)平台,用于快速开发物联网项目和管理拓展.https://github.com/pnoker/iot-dc3 在wind ...

  5. CentOS7上 定时执行sql文件,恢复数据库内的数据

    编写脚本stuinfo.sh #! /bin/bash TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"` #时间戳 LOG=/usr/local/xxx/ ...

  6. linux设置定时执行脚本文件

    假设我们想要每隔10分钟.每隔一天.每天3点执行一个脚本文件,那么[crontabs]就是我们需要使用的工具 目录 1.安装crontabs并启动 2.编辑需要运行的脚本 3.运行并编辑定时任务 4. ...

  7. linux执行脚本提示文件忙,linux定时执行脚本文件fgo 封号吗

    当我们要移动控制项(Control)或表单(Form)时,很多人习惯这样写: frmCustomer.Left=frmCustomer.Left 100 frmCustomer.Top=frmCust ...

  8. python 选择不同数据库环境执行SQL文件

    在有很多SQL文件,或者很多SQL语句的时候,如果手动每个文件执行会很麻烦:另外有的时候SQL语句的执行会影响用户的使用效果,需要在晚上没有用户使用网站的情况下执行SQL语句,也就是晚上定时执行SQL ...

  9. Linux 定时执行shell 脚本

    2019年第 85 篇文章,总第 109 篇文章 本文大约2000字,阅读大约需要6分钟 crontab 可以在指定的时间执行一个shell脚本以及执行一系列 Linux 命令. 定时执行shell ...

最新文章

  1. map中的erase成员函数用法
  2. P5735 【深基7.例1】距离函数(python3实现)
  3. 重磅汇总!2015-2019学硕国家线走势情况!
  4. 4.3Python数据处理篇之Matplotlib系列(三)---plt.plot()折线图
  5. linux下oracle10g安装配置说明,Linux下oracle10g安装配置说明(ZT)
  6. 学习官方示例 - TApplication.ExeName
  7. IOS开发学习笔记007-数据结构
  8. f-stack nginx 单进程模式BSD网络初始化流程
  9. dotnet core在Linux下运行的步骤
  10. compaq 515 安装声卡驱动IDT后耳机无声音
  11. linux系统如何安装bt5,BT5硬盘安装(多系统linux + win + BT5)
  12. 因子分析法(Matlab与SPSS对比)
  13. ER图向关系模型的转换
  14. 腾讯qq空间GET登陆JS分析
  15. 鸿蒙系统安装电视猫,免费资源丰富 如何让智能电视物尽其用
  16. 萌新必看——10种客户端存储哪家强,一文读尽!
  17. 如何高效利用GitHub
  18. UIP协议栈移植到u-boot详解
  19. python数据的容器
  20. 【Java】- JDK是什么?

热门文章

  1. 云服务器上部署pytorch,flask部署pytorch-服务端
  2. mysql存储数组类型的数据_mysql中怎么存储数组
  3. 谷歌Chrome浏览器开发者工具教程—基础功能篇
  4. 计算机组成原理试卷分析,《计算机组成原理与汇编语言》试卷分析报告.doc.docx...
  5. Andrew ng清华报告听后感
  6. 机构关注的数据治理问题
  7. python打不开settings_python - django无法导入settings文件
  8. python 线程同步_python线程同步(2)
  9. 文字识别(五)--自然场景文本检测技术综述(CTPN, SegLink, EAST)
  10. html中心点缩放,html canvas 让物体随物体中心缩放