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());
}
}
}