【发布时间】:2011-03-03 21:05:01
【问题描述】:
我写了一个 Thread.descendent 类,在执行方法中我放了一个无限循环来监听一个 com 事件,被认为是一个不好的线程实践使用无限循环来做到这一点?应用程序工作正常,不会冻结并且总是响应,我只是回答,因为我想使用最好的线程方法。
procedure TMyThread.Execute;
begin
while True and not Terminated do
begin
AResult:= FListener.GetResult(Param1,Param2,5000);
if not VarIsNull(AResult) then
Synchronize(Process);
end;
end;
【问题讨论】:
-
如果有一个事件终止了循环,那现在就不是无限的了吧?
-
如果没有事件,FListener.GetResult 是否等待?
-
要停止我使用
TMyThread.Terminate的线程,请检查while True and not Terminated do行,我检查线程是否已终止。 ` -
大卫,我更新了代码,监听器方法有一个超时参数,以毫秒为单位等待。
-
true and A与任何A的A相同。
标签: multithreading delphi