当前位置: 移动技术网 > IT编程>开发语言>.net > .net 全局定时定期执行某些操作 Global.asax

.net 全局定时定期执行某些操作 Global.asax

2018年11月03日  | 移动技术网IT编程  | 我要评论

捅马蜂窝冯骥才,屌丝之城,高清电影网

<%@ application language="c#" %>
<%@ import namespace="system.data"  %>
<%@ import namespace="system.data.sqlclient"  %>
<%@ import namespace="system.collections" %>
<%@ import namespace="system.io" %>

//引入类库

<script runat="server">

    //add by chairuirui 2013-3-26
    void application_start(object sender, eventargs e)
    {
        //在应用程序启动时运行的代码
        system.timers.timer mytimer = new system.timers.timer(60000); // 每个一分钟判断一下
        mytimer.elapsed += new system.timers.elapsedeventhandler(ontimedevent); //执行需要操作的代码,ontimedevent是要执行的方法名称
        mytimer.interval = 60000;
        mytimer.enabled = true;
    }
   
    void application_end(object sender, eventargs e)
    {
        //在应用程序关闭时运行的代码

    }
       
    void application_error(object sender, eventargs e)
    {
        //在出现未处理的错误时运行的代码

    }

    void session_start(object sender, eventargs e)
    {
        //在新会话启动时运行的代码

    }

    void session_end(object sender, eventargs e)
    {
        //在会话结束时运行的代码。
        // 注意: 只有在 web.config 文件中的 sessionstate 模式设置为
        // inproc 时,才会引发 session_end 事件。如果会话模式
        //设置为 stateserver 或 sqlserver,则不会引发该事件。

    }


    private static void ontimedevent(object source, system.timers.elapsedeventargs e)
    {

        //需要的操作写在这个方法中

    }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网