WebRequest.GetResponse锁起来? [英] WebRequest.GetResponse locks up?

查看:153
本文介绍了WebRequest.GetResponse锁起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上的GetResponse写我下面的code锁了起来。为什么呢?

 尝试
        {
            WebRequest的myWebRequest = WebRequest.Create(strURL);
            WebResponse类myWebResponse = myWebRequest.GetResponse();
            //更多code在这里
 

解决方案

这通常发生,如果你做了一些请求到同一台主机,而不是被处置的 WebResponse类

默认的连接管理设置只允许2(或者4,我不记得了),打开连接到同一主机的时间。如果你的真正的需要改变这一点,使用<一个href="http://msdn.microsoft.com/en-us/library/fb6y0fyc.aspx"><$c$c><connectionManagement> app.config中的元素 - 但通常你会没事的只是处置 WebResponse类

 尝试
{
    WebRequest的myWebRequest = WebRequest.Create(strURL);
    使用(WebResponse类myWebResponse = myWebRequest.GetResponse())
    {
        //更多code在这里
 

When writing the below my code locks up on GetResponse. Why?

        try
        {
            WebRequest myWebRequest = WebRequest.Create(strURL);
            WebResponse myWebResponse = myWebRequest.GetResponse();
            //more code here

解决方案

This usually happens if you've made several requests to the same host, and not disposed of the WebResponse.

The default connection management settings only allow 2 (or maybe 4, I can't remember) open connections to the same host at a time. If you really need to change this, use the <connectionManagement> app.config element - but usually you'll be fine just disposing of WebResponse:

try
{
    WebRequest myWebRequest = WebRequest.Create(strURL);
    using (WebResponse myWebResponse = myWebRequest.GetResponse())
    {
        //more code here

这篇关于WebRequest.GetResponse锁起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆