首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于多线程下载总是有失败的困扰,请高手帮忙看看代码有什么有关问题(100分)

2012-04-25 
关于多线程下载总是有失败的困扰,请高手帮忙看看代码有什么问题(100分)。以下是具体的代码实现,请高手看看

关于多线程下载总是有失败的困扰,请高手帮忙看看代码有什么问题(100分)。
以下是具体的代码实现,请高手看看有没有需要改进的地方。谢谢!

Delphi(Pascal) code
procedure TDownload.Execute;var  idHTTP : TIdHTTP;  isExcetpion:Boolean;  urlindex:integer;  url1:string;begin  urlindex:=aManager.ThisJob.iUrlIndex;  iLeft := aManager.arDLFThread[iIndex].iOffsetEnd - iThisBegin;  aManager.arThisDownloadSize[iIndex] := 0;    Repeat     begin        isExcetpion:= true;        idHTTP := TidHTTP.Create(nil);        try          iThisBegin := aManager.arDLFThread[iIndex].iOffsetBegin + aManager.arDLFThread[iIndex].iOffsetDownload;          idHTTP.HandleRedirects := True;          idHTTP.ReadTimeout := 30000;          idHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Maxthon)';            idHTTP.Request.Connection:='Keep-Alive';          idHTTP.Request.ContentRangeStart := iThisBegin;          idHTTP.Request.ContentRangeEnd := aManager.arDLFThread[iIndex].iOffsetEnd;          url1:=aManager.thisJob.iUrls[urlindex];          idHTTP.DoRequest(hmGet, url1, nil, nil);          while not aManager.arStop[iIndex] and (iLeft > 0) do            if iLeft > BufferSize then            begin              idHTTP.ReadBuffer(Buffer, BufferSize);              fs.WriteBuffer(Buffer, BufferSize);              aManager.arDLFThread[iIndex].iOffsetDownload := aManager.arDLFThread[iIndex].iOffsetDownload + BufferSize;              aManager.arThisDownloadSize[iIndex] := aManager.arThisDownloadSize[iIndex] + BufferSize;              iLeft := iLeft - BufferSize;              aManager.arDLFThread[iIndex].iState := 1;            end          else            begin              idHTTP.ReadBuffer(Buffer, iLeft);              fs.WriteBuffer(Buffer, iLeft);              aManager.arDLFThread[iIndex].iOffsetDownload := aManager.arDLFThread[iIndex].iOffsetDownload + iLeft;              aManager.arThisDownloadSize[iIndex] := aManager.arThisDownloadSize[iIndex] + iLeft;              iLeft := 0;              aManager.arDLFThread[iIndex].iState := 1;            end;            isExcetpion := true;          except            isExcetpion := false;            if urlindex<aManager.ThisJob.iurlsCount-1 then            begin              urlindex:=urlindex+1;            end            else            begin              urlindex:=0;              aManager.arDLFThread[iIndex].iState := 2;            end;          end;        idHTTP.Free;      end;    until isExcetpion;    fs.Free;    aManager.arStop[iIndex] := False;    aManager.arStoped[iIndex] := True;    aManager.arDLFThread[iIndex].iState := 1;  end;


[解决办法]
认真阅读这篇文章中的回复
推荐使用WinInet库,
http://www.delphi2007.net/DelphiNetwork/html/reply_2003051009102116999.html
相信对你肯定有帮助
[解决办法]
线程方面我也不太会,关注你的帖子中

热点排行