我使用VSTS 2008 + C#+ .Net 3.5開發控制檯應用程序,並向另一臺服務器(Windows Server 2008上的IIS 7.0)發送請求。這是我的代碼。我的問題是,就像在我的代碼中一樣,我使用while循環來從服務器讀取塊。 Timeout = Timeout * 1000負責(1)打開連接到服務器的超時時間,或者(2)每次讀取操作的超時時間,或者(3)while循環的總時間?Http請求超時問題
static void PerformanceWorker()
{
Stream dataStream = null;
HttpWebRequest request = null;
HttpWebResponse response = null;
StreamReader reader = null;
try
{
request = (HttpWebRequest)WebRequest.Create(TargetURL);
request.Timeout = Timeout * 1000;
request.Proxy = null;
response = (HttpWebResponse)request.GetResponse();
dataStream = response.GetResponseStream();
reader = new StreamReader(dataStream);
// 1 M at one time
char[] c = new char[1000 * 10];
while (reader.Read(c, 0, c.Length) > 0)
{
globalCounter++;
}
}
catch (Exception ex)
{
lock (counterLock)
{
globalFailCounter++;
Console.WriteLine("Fail Counter: " + globalFailCounter + "\n" + ex.Message + "\n" + ex.StackTrace);
}
}
finally
{
if (null != reader)
{
reader.Close();
}
if (null != dataStream)
{
dataStream.Close();
}
if (null != response)
{
response.Close();
}
}
}
謝謝,我從現在開始照顧它。 :-) – George2 2009-10-21 04:56:11