none
c# Windows Mobile下HttpWebRequest请求几次后不再发出请求 RRS feed

  • 问题

  • 代码如下所示:
      public void remotebidui(object res)
            {
                //去远程取回XML文档,然后解析XML文档
                 ReturnResult result = new ReturnResult();
                try
                {
                    result = (ReturnResult)res;
                    //res
                }
                catch (Exception err)
                {
                    MessageBox.Show("cast",err.Message);
                }
                this.sfzh = result.sValue;
                this.strStatusValue = result.returnRange;
                try
                {
                   
                     if (strStatusValue.Equals("在逃"))
                    {
                        rangeStr = "10000000";
                       
                    }
                    if (sfzh != "") { URI = config.biduiurl + "?pid=" + sfzh+"&range="+rangeStr; }
                   // MessageBox.Show("sfzh:"+sfzh+",uri:"+config.biduiurl+",pid:"+sfzh+",range:"+rangeStr);
                    // InternetSetCookie(URI, "", config.cookie);
                    HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest;
                    request.Headers.Add("COOKIE",config.cookie);
                    request.Method = "GET";
                    request.KeepAlive = false;
                    request.Timeout = 120000;
                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    System.IO.Stream responseStream = response.GetResponseStream();
                    System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.Default);
                    string srcString = reader.ReadToEnd();
                  //  MessageBox.Show("srcString:" + srcString);
                    request = null;
                   
                  //  request.ServicePoint.ConnectionLimit = 8;
                   // request.ServicePoint.ConnectionLimit = 200;
                    response.Close();
                    reader.Close();
                    reader.Dispose();
                    responseStream.Close();
                    responseStream.Dispose();
                    delegateEvent additemevent = additem;
                   
                    ReturnResult result1 = new ReturnResult();
                    result1.sValue = srcString;
                    result1.returnRange = rangeStr;
                    if (additemevent != null)
                    {
                        additemevent(result1);
                    }
                }
                catch (Exception ee)
                {
                       string s = "<root><alarm>" + ee.Message + "</alarm><sfzh></sfzh><xm></xm><description></description></root>";
                  //  MessageBox.Show("000000");    
                    delegateEvent additemevent = additem;
                    ReturnResult result1 = new ReturnResult();
                 //   MessageBox.Show("1111");
                    result1.sValue = s;
                    //result1.returnRange = "00000000";
                    result1.returnRange = rangeStr;
                    if (additemevent != null)
                    {
                        additemevent(result1);
                    }
                }
                finally {
               
                }
               

            }
    使用线程进行请求:
      if (strStatue.Substring(0, 1).Equals("1"))
                {

                    ReturnResult result = new ReturnResult();
                    result.returnRange = "在逃";
                    result.sValue = sfzh;
                    object obj = (object)result;
                    bidui bd = new bidui(obj);
                    bd.additem += AddItemEvent;
                    WaitCallback w = new WaitCallback(bd.remotebidui);
                    ThreadPool.QueueUserWorkItem(w, obj);

                }
               
    出现问题: webrequest请求几次后就没反应了,一般request能请求个10来次就死掉了。
    请大家帮忙解决,谢谢!!

    2010年4月1日 12:55

答案

全部回复