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