2013-03-03 16 views
1
for (int i = 0; i < endurance/10; i++) { 
    log.Info("mining now : " + endurance/10 + " - " + i); 
    HttpWebRequest mineRequest = WebRequestUtil.CreateHttpWebRequest(Properties.Settings.Default.PAGE_URL + Properties.Settings.Default.MINING_URL); 

    string source = SourceParser.GetSource(mineRequest); // GETTING TIMED OUT HERE 
    string variable = GetHiddenVariableNumber(source); 

    Mine(variable); 
} 

我的方法的getSource:的HttpWebRequest在第三次嘗試超時,只有兩個連接允許HTTP 1.1

public static string GetSource(WebRequest request) { 
    using (WebResponse response = request.GetResponse()) { 
     using (Stream stream = response.GetResponseStream()) { 
      using (StreamReader reader = new StreamReader(stream)) { 
       return reader.ReadToEnd(); 
      } 
     } 
    } 
} 

LOG:

2013-03-03 02:10:56,101 [13] INFO Bot.Game.Mining mining now : 10 - 0 
2013-03-03 02:10:57,053 [13] INFO Bot.Game.Mining mining now : 10 - 1 
2013-03-03 02:10:58,155 [13] INFO Bot.Game.Mining mining now : 10 - 2 // ends here 

有什麼建議?我讀了很多關於它和通常的問題是不處理StreamWebResponse對象,但我這樣做。

回答

3

我認爲這可能是ServicePoint的問題。它爲HTTP連接提供連接管理。

ServicePoint對象允許的默認最大併發連接數是2.所以如果你需要增加它,你可以使用ServicePointManager.DefaultConnectionLimit屬性。

+0

是的,但他們最終會結束,我需要的是以某種方式關閉連接。那可能嗎? – Jaanus 2013-03-03 07:18:44

相關問題