1 Public voidDisposereportdata (synfileinfo Item)2 {3Mreport report =Newmreport ();4Report. File name =item. DocName;5Report. URL =item. Downpath;6HttpWebRequest request =NULL;7HttpWebResponse response =NULL;8 Try9 {TenRequest = WebRequest.Create (item. Downpath) asHttpWebRequest; OneRequest. Proxy =NULL;//do not use proxies. The default proxy in NET4.0 is turned on ARequest. KeepAlive =false;//do not establish a persistent connection -Request. Timeout = the;//time-out for connection URLs -Request. Readwritetimeout = the;//time-out for reading URL content theResponse = Request. GetResponse () asHttpWebResponse; - LongLength =Response. ContentLength; - stringSize = fileoperate.getautosizestring (length,2); -report. Size =size; +Report. Connection Status ="effective"; - } + Catch(WebException webEx) A { atreport. Size ="0 MB"; -Report. Connection Status ="Invalid"; -Console.WriteLine ("The requested file does not exist!"+webex.message); - } - finally - { in Lock(Configreader.reportdata) - { to CONFIGREADER.REPORTDATA.ADD (report); + } - if(Response! =NULL) the { *Response. Close ();//Close Connection $ }Panax Notoginseng if(Request! =NULL) - { theRequest. Abort ();//Abort Request + } ARequest =NULL; theResponse =NULL; +System.GC.Collect ();//force garbage Collection, and release resources - $ } $}
View Code
WebRequest Multithreading Timeout problem
System.Net.ServicePointManager.DefaultConnectionLimit = ; the maximum number of concurrent,. NET default concurrency is only 2
C # Create a connection through HttpWebRequest to get the file size determine whether a file of the HTTP type exists