这个是我的线程程序,应该没有问题吧。是修改了ics的例子。<br>挂起用 <br>if not Terminated then<br> Synchronize(UpdateStatus);<br>最总会调用 ThreadsObjects[ThreadNumber].Suspend;<br>把线程挂起。<br><br>unit HttpThrClass;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> HttpProt;<br><br>type<br> THTTPThread = class(TThread)<br> private<br> FProgress: string;<br> procedure UpdateStatus;<br> procedure ShowProgress;<br>// procedure Progress(Msg: string);<br>// procedure DocBegin(Sender: TObject);<br>// procedure DocData(Sender: TObject; Buffer: Pointer; Len: Integer);<br>// procedure DocEnd(Sender: TObject);<br> published<br> procedure Setup(i: Integer);<br> procedure Execute; override;<br> public<br> FURL: string;<br> FProxy: string;<br> Keyword: string;<br> FThreadNumber: Integer;<br> FHttpCli: THTTPCli;<br> Success: Boolean;<br> end;<br><br>implementation<br><br>uses<br> mainform;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.Setup(i: Integer);<br>begin<br> FThreadNumber := i;<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.UpdateStatus;<br>begin<br> form1.ProcessResults(FThreadNumber, Success);<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.ShowProgress;<br>begin<br> form1.SetVTValue(FThreadNumber,4,2);<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.Progress(Msg: string);<br>begin<br> FProgress := Msg;<br> SynChronize(ShowProgress);<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.Execute;<br>begin<br> FHttpCli := THTTPCli.Create(nil);<br> FHttpCli.MultiThreaded := TRUE;<br> FHttpCli.RcvdStream := TMemoryStream.Create;<br>// FHttpCli.OnDocBegin := DocBegin;<br>// FHttpCli.OnDocEnd := DocEnd;<br>// FHttpCli.OnDocData := DocData;<br> while not Terminated do<br> begin<br>// Progress(IntToStr(FThreadNumber) + ' Start get');<br> with FHttpCli do<br> begin<br> URL := FURL;<br> //Proxy := FProxy;<br> (RcvdStream as TMemoryStream).Clear;<br> try<br> Get; // Get page from internet<br> Success := TRUE;<br> except<br> Success := FALSE;<br> end;<br> end;<br> if not Terminated then<br> Synchronize(UpdateStatus);<br> end;<br><br> if FHttpCli.RcvdStream <> nil then<br> FHttpCli.RcvdStream.Free;<br><br> FHttpCli.Free;<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.DocBegin(Sender: TObject);<br>begin<br> Progress(IntToStr(FThreadNumber) + ' Doc begin');<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.DocData(Sender: TObject; Buffer: Pointer; Len: Integer);<br>begin<br> Progress(IntToStr(FThreadNumber) + ' Doc data');<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.DocEnd(Sender: TObject);<br>begin<br> Progress(IntToStr(FThreadNumber) + ' Doc end');<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>end.<br>