var
th:a:procedure a.Execute ;
begin
try
FreeOnTerminate := true;
.....
finally
th.Terminate;
end;
end;有没有可能程序运行到了th.Terminate,但是线程没有真正结束?
th:a:procedure a.Execute ;
begin
try
FreeOnTerminate := true;
.....
finally
th.Terminate;
end;
end;有没有可能程序运行到了th.Terminate,但是线程没有真正结束?
解决方案 »
- 请问如果用dspack或者DirectShow播放在线mp3文件呢?
- 在treeview里加了个右键菜单,结果第一个按钮没问题,第二个只要一输入不管什么都是 unable to invoke code completion due to errors
- 请问每天一个ACCESS数据库,我想查询多天,怎么把这几个数据库组合一起查询?
- 请问Delphi的Delete函数如何使用?
- COM技术,关于注册问题。
- 研究了一下午,还是没解决,救命呀~~~~~~
- 奉一套类似于oicq的源代码,(用delphi6.0编写的)(不过要决以下问题)
- dxbarmanager控件如何修改字体大小
- delphi7 滚动条颜色
- 怎样做半透明窗体!!!
- 不同内网间的UDP通讯?
- 报错List index out of bounds (1),越界错误。。求解。。
var
FreeThread: Boolean;
begin
{$IFDEF LINUX}
if Thread.FSuspended then sem_wait(Thread.FCreateSuspendedSem);
{$ENDIF}
try
if not Thread.Terminated then
try
Thread.Execute;
except
Thread.FFatalException := AcquireExceptionObject;
end;
finally
FreeThread := Thread.FFreeOnTerminate;
Result := Thread.FReturnValue;
Thread.DoTerminate;
Thread.FFinished := True;
SignalSyncEvent;
if FreeThread then FreeAndNil(Thread);
{$IFDEF MSWINDOWS}
EndThread(Result);
{$ENDIF}
{$IFDEF LINUX}
// Directly call pthread_exit since EndThread will detach the thread causing
// the pthread_join in TThread.WaitFor to fail. Also, make sure the EndThreadProc
// is called just like EndThread would do. EndThreadProc should not return
// and call pthread_exit itself.
if Assigned(EndThreadProc) then
EndThreadProc(Result);
pthread_exit(Pointer(Result));
{$ENDIF}
end;
end;
1、在子线程内构造一个循环,访问事件对象;
2、可以waitforSingleObject,等待事件对象,有信号时,则执行;
3、主线程需要子线程“干活”时,设置事件对象为有信号状态即可;
4、注意应用场合,调整线程优先级,分析子线程可能获得执行的几率