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)
            {
            //需要定时执行的逻辑
            }        
  • 相关阅读:
    237. 删除链表中的节点
    牛客网-第一场-J-Fraction Comparision
    1. 两数之和
    CCF-201903-1大中小
    学习Python
    Convert Sorted Array to Binary Search Tree
    3-1
    Merge Sorted Array
    Climbing Stairs
    Add Binary
  • 原文地址:https://www.cnblogs.com/youmeng/p/3278931.html
Copyright © 2011-2022 走看看