using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; using System.Net; using System.IO; using System.Threading; using Logger; using System.Timers; using Untitly; using System.Runtime.Remoting.Messaging; namespace WebApplication1 { public class Global : System.Web.HttpApplication { //定义定时器 private myTimer m; protected void Application_Start(object sender, EventArgs e) { new Thread((ThreadStart)delegate() { m= Singleton<myTimer>.getInstance(); m.time(); }) .Start(); } 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) { Exception ex = Server.GetLastError().GetBaseException(); Log.WriteErrorLog(ex); } protected void Session_End(object sender, EventArgs e) { } protected void Application_End(object sender, EventArgs e) { //下面的代码是关键,可解决IIS应用程序池自动回收的问题 Thread.Sleep(1000); //这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start string url = "/default.aspx"; HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流 } } }