zoukankan      html  css  js  c++  java
  • 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 = 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);
            }
        }
  • 相关阅读:
    ITPUB:按道理应该走的局部分区索引
    如何用正则取美国人名.
    Commit Enhancements in Oracle 10g Database Release 2
    关羽(162219)
    使用Oracle在线重定义包 DBMS_REDEFINITION 在不停业务的情况下增加或修改字段
    Online Table Redefinition Enhancements in Oracle Database 11g Release 1
    关于分区表和分区索引
    如何切换用户到不同用户Session上
    PL/SQL Enhancements in Oracle Database 10g
    Using Regular Expressions in Oracle Database
  • 原文地址:https://www.cnblogs.com/-hao/p/9944813.html
Copyright © 2011-2022 走看看