运行线程应用程序后无法在所有浏览器中浏览所有站点
我有一个奇怪的问题,我不确定它来自哪里。 昨晚我开始申请时就开始了。
我有以下代码:
DateTime startTime = DateTime.Now;
WebRequest req = (WebRequest)HttpWebRequest.Create("http://" + server + url + action);
WebResponse res = req.GetResponse();
try
{
using (StreamReader reader = new StreamReader(res.GetResponseStream()))
{
string response = reader.ReadToEnd();
TestInfo.CheckMsg retMsg;
// individual Test
retMsg = indFunc(req.RequestUri.ToString(), response);
printMessage(retMsg, req, res, startTime);
if (retMsg.SeverityLevel > TestInfo.CheckMsg.Severity.Warning)
return;
// group Test
retMsg = groupFunc(relatedGroup, req.RequestUri.ToString(), response);
printMessage(retMsg, req, res, startTime);
if (retMsg.SeverityLevel > TestInfo.CheckMsg.Severity.Warning)
return;
// common Test
retMsg = commonFunc(req.RequestUri.ToString(), response);
printMessage(retMsg, req, res, startTime);
if (retMsg.SeverityLevel > TestInfo.CheckMsg.Severity.Warning)
return;
reader.Close();
};
}
catch (Exception e)
{
Console.WriteLine("EXCEPTION WAS THROWN!!!!! " + e.Message);
}
finally
{
res.Close();
}
该函数在多个线程上运行。 经过多次应用程序调试后,此代码无法连接,并声称底层连接已关闭。 当尝试在我的计算机(WIN XP)中的所有浏览器中浏览所有站点时,我要么得到空白页面,要么在 Chrome 中得到服务器的响应为空。
只有 Http 被搞砸了,而其他 TCP 连接却可以工作!
所以我猜问题可能出在我的代码中(也许有些东西没有发布???)
让我知道你对代码的看法。
谢谢
I have a weird problem and I am not sure where is it coming from.
Started last night when I started my application.
I have the following code:
DateTime startTime = DateTime.Now;
WebRequest req = (WebRequest)HttpWebRequest.Create("http://" + server + url + action);
WebResponse res = req.GetResponse();
try
{
using (StreamReader reader = new StreamReader(res.GetResponseStream()))
{
string response = reader.ReadToEnd();
TestInfo.CheckMsg retMsg;
// individual Test
retMsg = indFunc(req.RequestUri.ToString(), response);
printMessage(retMsg, req, res, startTime);
if (retMsg.SeverityLevel > TestInfo.CheckMsg.Severity.Warning)
return;
// group Test
retMsg = groupFunc(relatedGroup, req.RequestUri.ToString(), response);
printMessage(retMsg, req, res, startTime);
if (retMsg.SeverityLevel > TestInfo.CheckMsg.Severity.Warning)
return;
// common Test
retMsg = commonFunc(req.RequestUri.ToString(), response);
printMessage(retMsg, req, res, startTime);
if (retMsg.SeverityLevel > TestInfo.CheckMsg.Severity.Warning)
return;
reader.Close();
};
}
catch (Exception e)
{
Console.WriteLine("EXCEPTION WAS THROWN!!!!! " + e.Message);
}
finally
{
res.Close();
}
This function runs on several threads.
After several application debugging this code fails to connect claiming UNDERLYING CONNECTION WAS CLOSED.
when trying to browse in my computer (WIN XP) in all browsers to all sites I get either blank page or in chrome I get that the response from the server was empty.
Http only is screwed while other TCP connections work!
So I guess the problem might be in my code (maybe something is not released???)
Let me know what do you think of the code.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确实认为错误的一件事是您需要移入
try 块,因为它可能会引发异常(MSDN)。我还会添加一个空检查:
One thing I do see wrong is that you need to move
Into your try block bc it can throw an exception(MSDN). I would also add a null check to: