zoukankan      html  css  js  c++  java
  • C#定时执行任务

    1、在项目开发的中,经常会遇到要定时执行的任务,今天我们写一个在Global.asax.cs程序中的定时任务写法。

    因为项目执行是从Application_Start() 方法开始的,所以我们写定时任务,需要将定时计划在这个方法中定义。

    将下面代码放在Application_Start() 方法的最后面。

    1  #region 预警消息推送定时-5分钟一次
    2             
    3             int TimerS = 5 * 60 * 1000;
    4 
    5             System.Timers.Timer tm = new System.Timers.Timer(TimerS);
    6             tm.Elapsed += tm_Elapsed;
    7             tm.AutoReset = true;
    8             tm.Enabled = true;
    9             #endregion

    在Global.asax.cs新建一个定时任务的方法,如下所示

        //定时执行推送
            private void tm_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                SearchModuleBLL service = new SearchModuleBLL();
                service.PushSKMessages();
            }
     
  • 相关阅读:
    too many open files linux服务器 golang java
    fasthttp 文档手册
    syncer.go
    grpc.go
    stm.go
    session.go
    mutex.go
    [HTML5]label标签使用以及建议
    禁止使用finalize方法
    [支付宝]手机网站支付快速接入
  • 原文地址:https://www.cnblogs.com/MirZhai/p/13714277.html
Copyright © 2011-2022 走看看