zoukankan      html  css  js  c++  java
  • Web定时执行某个方法-网页获取

    实现该功能用到的是System.Timers.Timer

    将定时的方法添加到Global.ascx.cs中

    public class Global : System.Web.HttpApplication
        {
            protected 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 = AutoUpdateGoldPriceTime;
                    myTimer.Enabled = true;
                }
            }
    
            protected void Session_Start(object sender, EventArgs e)
            {
            }
    
            protected void Application_BeginRequest(object sender, EventArgs e)
            {
    
            }
    
            protected void Application_AuthenticateRequest(object sender, EventArgs e)
            {
    
            }
    
            protected void Application_Error(object sender, EventArgs e)
            {
    
            }
    
            protected void Session_End(object sender, EventArgs e)
            {
    
            }
    
            protected void Application_End(object sender, EventArgs e)
            {
    
            }
    
            protected  void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
            {
            //需要定时执行的逻辑
            }        
  • 相关阅读:
    php 类文件加载 Autoloader
    windows下配置nginx+php
    crontab 定时调度
    PHP 常见语法 集合
    php socket
    tengine + mysql + nginx + php
    yii2 [行为] behaviors 拦截器
    .htaccess 语法以及应用
    nginx 安装
    Nginx HTTP负载均衡和反向代理配置
  • 原文地址:https://www.cnblogs.com/youmeng/p/3278931.html
Copyright © 2011-2022 走看看