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)
            {
            //需要定时执行的逻辑
            }        
  • 相关阅读:
    《杜教筛》
    《洛谷P4213 【模板】杜教筛(Sum)》
    《洛谷P1829 [国家集训队]Crash的数字表格 / JZPTAB》
    《纸牌问题》
    《洛谷P2522 [HAOI2011]Problem b》
    使用urlretrieve下载图片
    scrapy初探
    爬豆瓣电影名
    直接插入排序
    Windows python 3 安装OpenCV
  • 原文地址:https://www.cnblogs.com/youmeng/p/3278931.html
Copyright © 2011-2022 走看看