我尝试使用
中的脚本但是当我尝试下载多个文件时,根据请求增加了下载站点(同一站点)所消耗的时间,结果是:
retrive time: 1500 ms
retrive time: 1500 ms
retrive time: 2721 ms
retrive time: 4089 ms
retrive time: 5255 ms
retrive time: 5708 ms
retrive time: 6485 ms
retrive time: 6916 ms
retrive time: 7421 ms
retrive time: 8139 ms
这是我的代码(注意:httpwebrequest keepalive已关闭):
static void Main()
{
for (int i = 0; i < 10; i++)
{
HttpWebRequest_BeginGetResponse req = new HttpWebRequest_BeginGetResponse();
new Thread(new ThreadStart(req.start))
{
IsBackground=true
}.Start();
}
Console.ReadLine();
}
这里是我放秒表的地方
IAsyncResult result =
(IAsyncResult)myHttpWebRequest.BeginGetResponse(new AsyncCallback(RespCallback), myRequestState);
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), myHttpWebRequest, DefaultTimeout, true);
Stopwatch wtch = new Stopwatch();
wtch.Start();
allDone.WaitOne();
wtch.Stop();
Debug.WriteLine("retrive time: "+wtch.ElapsedMilliseconds+" ms");
这样做的正确方法是什么?