解决IIS应用池回收造成Application_Start中定时执行程序停止的问题new
2016-04-26 12:23 houri 阅读(1214) 评论(0) 收藏 举报先贴上代码
protected void Application_End(object sender, EventArgs e)
{
//Application_End其他代码
try
{
System.Threading.Thread.Sleep(5000);
string webport = ConfigurationManager.AppSettings["webport"];
string strUrl = "http://localhost:"+webport;
// string strUrl = "www.baidu.com";
System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
System.Net.HttpWebResponse _HttpWebResponse = (System.Net.HttpWebResponse)_HttpWebRequest.GetResponse();
System.IO.Stream _Stream = _HttpWebResponse.GetResponseStream();//得到回写的字节流
}
catch (Exception ex)
{
LogHelper.Error(this.GetType().ToString(), ex);
}
}
部分源码来源网络,在调试中遇到了 Url无效问题。注意 url 必须 以 http:// 开始 ,否则就报 url无效。
url 就是自己iis网站的网址
浙公网安备 33010602011771号