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. Python:从入门到实践--第七章--用户输入和while循环-练习

    #1.编写一个程序,询问用户要租赁什么样的汽车,并打印. car = input("What's kind of cars dou you want to rent?,sir:") ...

  2. Codeforces 1105B:Zuhair and Strings(字符串水题)

    time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...

  3. 不同系统、不同存储格式(textfile, parquet)数据的传递

    描述: 本地测试环境hive中有数据,存储格式为textfile,现在要上传到公司开发环境,存储格式为parquet, 如何实现??? tb_textfile表---> local file - ...

  4. 虚拟机无法上网,没有eth0

    虚拟机无法上网,找不到eth0解决方案如下: Ifconfig -a 第一步,输入如下命令,编辑对应文件(使用管理员权限执行,下同) # vim /etc/default/grub 在"GR ...

  5. 15. Password auditing (密码审核 12个)

    Aircrack是一套用于802.11a / b / g WEP和WPA破解的工具. 一旦收集到足够的加密数据包,它就会实现最有效的破解算法来恢复无线密钥.. 该套件包括十多个分离工具,包括airod ...

  6. postman测试请求参数中文乱码问题

    用IDEA调试代码时,用postman测试请求url,发现post或者get请求中参数是中文的话,后台获取的参数是乱码, 一般两个方面 发送请求的一方:postman的问题 接受请求的一方:tomca ...

  7. 命令行编译多个java文件

    如何使用命令行编译多个java文件 文件结构: method 1 cd javaproject javac -sourcepath javapath -d classpath javapath/*.j ...

  8. Android L2TP Client Setup

    原文链接:http://www.softether.org/4-docs/2-howto/9.L2TPIPsec_Setup_Guide_for_SoftEther_VPN_Server/3.Andr ...

  9. 打印杨辉三角—Python

    b=[] for i in range(0,9): c=[] for j in range(0,i): if j==0: c.append(b[i-1][j]) if j<=i-2:#执行完第一 ...

  10. Jenkins 部署自动化测试脚本(15)

    自动化测试脚本开发完成以后,希望可以把脚本放在公共的环境下提供一个入口供大家一起使用,目前最好的解决方案就是需要把代码部署在Jenkins上,下面看下如何在Jenkins配合自动化测试任务: 1.首先 ...