我使用这段代码片段来验证URL中指定的文件是否存在,并每隔几秒钟为每个用户尝试一次。有时候(主要是当有大量用户使用该站点时),代码无法正常工作。
[WebMethod()]
public static string GetStatus(string URL)
{
bool completed = false;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
try
{
if (response.StatusCode == HttpStatusCode.OK)
{
completed = true;
}
}
catch (Exception)
{
//Just don t do anything. Retry after few seconds
}
}
return completed.ToString();
}
当我查看Windows事件日志时,有几个错误:
Unable to read data from the transport connection. An existing connection was forcibly closed
The Operation has timed out
The remote host closed the connection. The error code is 0x800703E3
当我重新启动综合调查时,事事到下一次发生为止。