c#webrequest挂起
我正在做一个项目,它多次调用一个网址c#webrequest挂起,c#,.net,C#,.net,我正在做一个项目,它多次调用一个网址 request = (HttpWebRequest)WebRequest.Create(url); request.GetResponse(); 这是我的密码。它在一个循环中,工作了2次,但在第三次迭代中挂起。没有崩溃或错误。请帮忙。任何帮助都将不胜感激 错误:等待20分钟后 System.Net.WebException was unhandled Message=The operation has timed out Source=System
request = (HttpWebRequest)WebRequest.Create(url);
request.GetResponse();
这是我的密码。它在一个循环中,工作了2次,但在第三次迭代中挂起。没有崩溃或错误。请帮忙。任何帮助都将不胜感激
错误:等待20分钟后
System.Net.WebException was unhandled
Message=The operation has timed out
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at ConsoleApplication1.Program.Main(String[] args) in C:\WorkSpace\ConsoleApplication1\ConsoleApplication1\Program.cs:line 48
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:请尝试以下操作:
var response = request.GetResponse();
//do stuff with response
response.Close();
WebResponse
实例保持活动连接,在建立到同一服务器的新连接之前,必须关闭该连接
您也可以使用using
子句来实现这一点,这完全取决于您:
using (var response = request.GetResponse())
{
//do stuff with response
}
你关闭了连接吗?谢谢你救了我-我的C#程序最终被锁定了,因为我没有关闭上面的回复!