2次有效请求然后超时
这是我的代码。它迭代数据库中的所有文件并尝试获取网络文件的长度。仅有效 2 次。之后它会超时。如果我重新启动应用程序,它会再次处理 2 个文件,然后失败。我不知道可能是什么问题。我很感激任何帮助。
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());
}
}
}
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());
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是否是给定客户端一次仅处理 2 个请求的默认行为的问题?在继续下一个请求之前是否需要强制关闭这些请求?也许这会让你突破 2 次命中限制。
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.