Website timed Operation Source code

Source: Internet
Author: User

Add code to the Global.asax file

<%@ application Language= "C #"%><script runat= "Server" > void Application_Start (object sender, EventArgs e)        {//code to run at application startup System.Timers.Timer MyTimer = new System.Timers.Timer (1000);//modify interval//correlation event        mytimer.elapsed + = new System.Timers.ElapsedEventHandler (mess);        Mytimer.autoreset = true;        System initialization code Application.Lock ();        application["Autoruncount"] = 0;        application["Laststart"] = DateTime.Now.ToString ();        Application.UnLock ();        Mytimer.enabled = true; Add additional code here} private void Mess (Object Sender,system.timers.elapsedeventargs e) {//Get current time Applicati On.        Lock (); if (Convert.ToInt32 (application["Autoruncount"]) < 99999999) application["autoruncount"] = Convert.ToInt32 (A        pplication["Autoruncount"]) + 1;        else application["Autoruncount"] = 0;        Application.UnLock ();        Write the code to execute in this//globalvar.sendmymail (); Set up a liftWake} void Application_End (object sender, EventArgs e) {//code to run at application shutdown///If an error occurs, remove the code below///below        The code is critical to address the problem of automatic collection of IIS application Pools System.Threading.Thread.Sleep (1000);        Set your web address here and you can point to any of your ASPX pages or even nonexistent pages to excite Application_Start string url = "Http://localhost:82/111.aspx";        System.Net.HttpWebRequest myhttpwebrequest = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (URL);        System.Net.HttpWebResponse myhttpwebresponse = (System.Net.HttpWebResponse) myhttpwebrequest.getresponse (); System.IO.Stream Receivestream = Myhttpwebresponse.getresponsestream ()///Get write-back byte stream//Add other code here} void A Pplication_error (object sender, EventArgs e) {//code to run in case of an unhandled error} void Session_Start (object sender, Eve         Ntargs e) {//code run at new session startup} void Session_End (object sender, EventArgs e) {//code that runs at the end of the session. Note: Sess is only raised if the sessionstate mode in the Web. config file is set to//InProcIon_end event.    If the session mode is set to StateServer//or SQL Server, the event is not raised. } </script>

Website timed Operation Source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.