2 valid requests and then timeout
Here is my code. It iterates all files from database and try to get the length of the web file开发者_高级运维. It works only 2 times. After that it gives timeout. If i restart the application it process again 2 files and then fail. I have no idea what might be the problem. I appreciate any help.
public void GetFilesSize()
{
List<int> ftl = new List<int>(){(int)eFileTypes.JADFile, (int)eFileTypes.SISFile, (int)eFileTypes.SITFile, (int)eFileTypes.ZIPFile };
foreach (File f in dc.Files.Where(fg => ftl.Contains(fg.FileTypeID) && fg.Size == 0))
{
try
{
WebRequest request = WebRequest.Create(new Uri(f.MSWebPath));
request.Method = "HEAD";
request.Timeout = 2000;
WebResponse response = request.GetResponse();
dc.Files.Single(f1 => f1.FileID == f.FileID).Size = (int)response.ContentLength;
dc.SubmitChanges();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
Could this be a problem with the default behavior of only 2 requests being processed at a time from a given client? Do the requests need to be forcibly closed before you proceed to the next one? Perhaps that would get you past the 2 hit limit.
精彩评论