1 public void DisposeReportData(SynFileInfo item) 2 { 3 MReport report = new MReport(); 4 report.文件名 = item.DocName; 5 report.URL = item.DownPath; 6 HttpWebRequest request = null; 7 HttpWebResponse response = null; 8 try 9 { 10 request = WebRequest.Create(item.DownPath) as HttpWebRequest; 11 request.Proxy = null;//不使用代理 .NET4.0中的默认代理是开启的 12 request.KeepAlive = false;//不建立持久性连接 13 request.Timeout = 5000;//连接网址的超时时间 14 request.ReadWriteTimeout = 5000;//读取网址内容的超时时间 15 response = request.GetResponse() as HttpWebResponse; 16 long length = response.ContentLength; 17 string size = FileOperate.GetAutoSizeString(length, 2); 18 report.大小 = size; 19 report.连接状态 = "有 效"; 20 } 21 catch (WebException webEx) 22 { 23 report.大小 = "0 MB"; 24 report.连接状态 = "无 效"; 25 Console.WriteLine("请求的文件不存在!" + webEx.Message); 26 } 27 finally 28 { 29 lock (ConfigReader.ReportData) 30 { 31 ConfigReader.ReportData.Add(report); 32 } 33 if (response != null) 34 { 35 response.Close();//关闭连接 36 } 37 if (request != null) 38 { 39 request.Abort();//中止请求 40 } 41 request = null; 42 response = null; 43 System.GC.Collect();//强制垃圾回收,并释放资源 44 45 } 46 }
System.Net.ServicePointManager.DefaultConnectionLimit = 20;//最大并发数,.net默认并发只有2个
时间: 2024-10-26 19:53:28