HttpWebRequest在30个线程之后开始超时

时间:2012-12-01 13:03:09

标签: c# multithreading httpwebrequest

我正在运行以下代码来启动我的主题:

        stpStartInfo.MaxWorkerThreads = Convert.ToInt32(parserThreadCount.Value);
        stpStartInfo.MinWorkerThreads = 1;
        _smartThreadPool2 = new Smart.SmartThreadPool(stpStartInfo);

        string f = sourceFileName.Text;
        int totCount = countLinesInFile(f);

        using (StreamReader r = new StreamReader(f))
        {
            int iia = 0;
            string line;
            while ((line = r.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(line)) 
                {
                    _smartThreadPool2.QueueWorkItem(
                    new Amib.Threading.Func<string, int, int, int>(checkSource),
                    line, iia, totCount);

                    iia++;
                }
            }
        }

我的线程正在执行此HttpWebRequest:

        try
        {
            HttpWebRequest _wReq;
            HttpWebResponse _wResp;
            System.IO.StreamReader _sr;
            System.Text.ASCIIEncoding _enc = new System.Text.ASCIIEncoding();
            _wReq = (HttpWebRequest)WebRequest.Create(PAGE_URL);
            _wReq.CookieContainer = cookieCont;
            _wReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            _wReq.ReadWriteTimeout = 10000;
            _wReq.Timeout = 10000;
            _wReq.ProtocolVersion = HttpVersion.Version10;
            _wReq.KeepAlive = false;





            _wResp = (HttpWebResponse)_wReq.GetResponse();
            _sr = new System.IO.StreamReader(_wResp.GetResponseStream());
            html = _sr.ReadToEnd();


            _sr.Close();
            _cookies = _wReq.CookieContainer;
            _wResp.Close();
        }
        catch (WebException ex)
        {

            if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
            {
                var resp = (HttpWebResponse)ex.Response;
                if (resp.StatusCode == HttpStatusCode.ServiceUnavailable)
                {

                }

            }
        }

它完美无缺,但在30个线程之后,请求开始超时..

知道怎么解决这个问题吗? :)

0 个答案:

没有答案