我正在使用 TThread,我只需要找出线程是否仍在运行并在运行时间过长时终止应用程序。
例如:
我使用 TThread,只需查找线程是否仍在运行并且如果运行时间太长,则终止应用程序。
MyThread := TMyThread.Create;
MyThread .Resume;
MyThread.Terminate;
total := 0;
while MyThread.isRunning = true do // < i need something like this
begin
// show message to user to wait a little longer we are still doing stuff
sleep(1000);
total := total + 1000;
if total > 60000 then
exit;
end;
Delphi可以实现这个吗?
Free
函数?我以为你想等到它完成后再释放资源。Finished
的实现很简单,你可以在线程类中添加一个布尔值,在Execute
函数退出时将其设置为 true。或者其他类似的方法。 - David Heffernan