ShellExecute使用怪现象。。。。。。。。(50分)

  • 主题发起人 主题发起人 一只笨小狗
  • 开始时间 开始时间

一只笨小狗

Unregistered / Unconfirmed
GUEST, unregistred user!
我一个程序,在后台开了5个线程挂起不干活,然后我点击主窗口下一个按钮,这个按钮<br>代码如下。<br>ShellExecute(Handle, 'open', Pchar('http://www.sina.com.cn'), nil, nil,SW_SHOW);<br><br>这个时候程序一点反应都没有,需要很长很长时间才能跳出ie。<br><br>如果我把5个线程free,点击按钮马上就可以跳出ie。<br><br>这个问题大家怎么解决的啊?
 
是你的线程寫的有問題。
 
我线程什么都没有干啊,就开了5个线程,然后挂起什么都不干。
 
把你的代码贴出来看看哦,应该是你线程的问题。
 
我先检查一下,看看线程那里出问题了。
 
这个是我的线程程序,应该没有问题吧。是修改了ics的例子。<br>挂起用 &nbsp; &nbsp;<br>if not Terminated then<br>&nbsp; &nbsp; &nbsp; Synchronize(UpdateStatus);<br>最总会调用 &nbsp;ThreadsObjects[ThreadNumber].Suspend;<br>把线程挂起。<br><br>unit HttpThrClass;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; HttpProt;<br><br>type<br>&nbsp; THTTPThread = class(TThread)<br>&nbsp; private<br>&nbsp; &nbsp; FProgress: string;<br>&nbsp; &nbsp; procedure UpdateStatus;<br>&nbsp; &nbsp; procedure ShowProgress;<br>// &nbsp; &nbsp;procedure Progress(Msg: string);<br>// &nbsp; &nbsp;procedure DocBegin(Sender: TObject);<br>// &nbsp; &nbsp;procedure DocData(Sender: TObject; Buffer: Pointer; Len: Integer);<br>// &nbsp; &nbsp;procedure DocEnd(Sender: TObject);<br>&nbsp; published<br>&nbsp; &nbsp; procedure Setup(i: Integer);<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; public<br>&nbsp; &nbsp; FURL: string;<br>&nbsp; &nbsp; FProxy: string;<br>&nbsp; &nbsp; Keyword: string;<br>&nbsp; &nbsp; FThreadNumber: Integer;<br>&nbsp; &nbsp; FHttpCli: THTTPCli;<br>&nbsp; &nbsp; Success: Boolean;<br>&nbsp; end;<br><br>implementation<br><br>uses<br>&nbsp; mainform;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.Setup(i: Integer);<br>begin<br>&nbsp; FThreadNumber := i;<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.UpdateStatus;<br>begin<br>&nbsp; form1.ProcessResults(FThreadNumber, Success);<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.ShowProgress;<br>begin<br>&nbsp; form1.SetVTValue(FThreadNumber,4,2);<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.Progress(Msg: string);<br>begin<br>&nbsp; FProgress := Msg;<br>&nbsp; SynChronize(ShowProgress);<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>procedure THTTPThread.Execute;<br>begin<br>&nbsp; FHttpCli := THTTPCli.Create(nil);<br>&nbsp; FHttpCli.MultiThreaded := TRUE;<br>&nbsp; FHttpCli.RcvdStream := TMemoryStream.Create;<br>// &nbsp;FHttpCli.OnDocBegin := DocBegin;<br>// &nbsp;FHttpCli.OnDocEnd := DocEnd;<br>// &nbsp;FHttpCli.OnDocData := DocData;<br>&nbsp; while not Terminated do<br>&nbsp; begin<br>// &nbsp; &nbsp;Progress(IntToStr(FThreadNumber) + ' Start get');<br>&nbsp; &nbsp; with FHttpCli do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; URL := FURL;<br>&nbsp; &nbsp; &nbsp; //Proxy := FProxy;<br>&nbsp; &nbsp; &nbsp; (RcvdStream as TMemoryStream).Clear;<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; Get; // Get page from internet<br>&nbsp; &nbsp; &nbsp; &nbsp; Success := TRUE;<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp; Success := FALSE;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if not Terminated then<br>&nbsp; &nbsp; &nbsp; Synchronize(UpdateStatus);<br>&nbsp; end;<br><br>&nbsp; if FHttpCli.RcvdStream &lt;&gt; nil then<br>&nbsp; &nbsp; FHttpCli.RcvdStream.Free;<br><br>&nbsp; FHttpCli.Free;<br>end;<br><br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.DocBegin(Sender: TObject);<br>begin<br>&nbsp; Progress(IntToStr(FThreadNumber) + ' Doc begin');<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.DocData(Sender: TObject; Buffer: Pointer; Len: Integer);<br>begin<br>&nbsp; Progress(IntToStr(FThreadNumber) + ' Doc data');<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br>{<br>procedure THTTPThread.DocEnd(Sender: TObject);<br>begin<br>&nbsp; Progress(IntToStr(FThreadNumber) + ' Doc end');<br>end;<br>}<br>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}<br><br>end.<br>
 
我测试了很长时间,我确实存在这个问题,我线程里是循环着的,程序不退出是不结束的,一般只是挂起。这个时候再使用ShellExecute(Handle, 'open', Pchar('http://www.sina.com.cn'), nil, nil,SW_SHOW);<br>就速度很慢很慢,需要半天才能跳出ie.<br>我写了个简单的测试程序,大家下回去看看是不是这样。<br>http://210.32.137.91/tmp/testsh.rar
 
请问:如果调用网上邻居怎么写啊?
 
问题解决了,换了个indy idhttp控间就好了。看来用ics我还是不怎么会。<br>帮助太少太不全了。
 
多人接受答案了。
 
后退
顶部