c# webrequest hangs
.net, c#
Solution
Try the following:
var response = request.GetResponse();
//do stuff with response
response.Close();
The `WebResponse` instance holds the active connection, and you have to close that connection before establishing new ones to the same server.
You could also do this with a `using` clause, it's really up to you:
using (var response = request.GetResponse())
{
//do stuff with response
}
Problem
I am working on a project, which call a web address many times ``` request = (HttpWebRequest)WebRequest.Create(url); request.GetResponse(); ``` Here is my code. It is in a loop, it work for 2 times but on third iteration it hangs. There is no crash or error. Kindly please help. Any help will be greatly appreciated. Error : After 20 min wait. ``` 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: