2011-05-25 15 views
0

我從c#應用程序中啓動參數化的Jenkins構建版本。從WebRequest.GetResponse間接重複超時連接到Jenkins/Hudson

這些網址是有效的(我可以將它從日誌中提取出來,並且沒有問題地運行它)。在某些時候,無論設置了多長時間(我已長達90秒)或運行了多少次,所有網絡請求都會超時。

這是間歇性的和某些時候,我根本沒有問題。

while (count<5)   
{ try{ 
        log.WriteEntry("RunningJenkinsBuild- buildURL=" + buildUrl, EventLogEntryType.Information); 
        WebRequest request = WebRequest.Create(buildUrl); 
        request.GetResponse(); 
        return; 
       } 
       catch (WebException ex) 
       { 
        log.WriteEntry("Timeout- wait 15 seconds and try again-"+ex.Message, EventLogEntryType.Error); 
        Thread.Sleep(15000); 
        count++; 
       } 
       catch (Exception ex2) 
       { 
        log.WriteEntry(ex2.Message, EventLogEntryType.Error); 
        return; 
       } 
      } 

回答

0

這清除了它。 '使用'幫助了它。

WebRequest請求= WebRequest.Create(buildUrl); request.Timeout = 10000;使用(WebResponse response = request.GetResponse()){} Thread.Sleep(5000);