views:

27

answers:

2

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());
            }
        }
    }
+1  A: 

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.

Peter
+1. Yes, this is the problem. You have to close the response. I had the same problem last week.
David
A: 

Thank you

I solved the problem in very ugly manner, a new console app witch execute 2 requests and die and a new console app that execute the first one until there is a work, it took less than 15 min to write it and it works :)

braikov