Delphi程序退出线程关闭有关问题ThreadList
Delphi程序退出线程关闭问题ThreadList
//所有的线程放在这里
ThreadList : TObjectList;
程序退出时,需要怎么关闭线程。
目前的关闭线程程序为
while ThreadList.Count > 0 do Application.ProcessMessages; //这里会不停的循环。ThreadList.Count=10,这里会死机。花费10分钟以上时间。
ThreadList.Free;
大家谁知道比较好的线程关闭方式。
------解决方案--------------------
//所有的线程放在这里
ThreadList : TObjectList;
程序退出时,需要怎么关闭线程。
目前的关闭线程程序为
while ThreadList.Count > 0 do Application.ProcessMessages; //这里会不停的循环。ThreadList.Count=10,这里会死机。花费10分钟以上时间。
ThreadList.Free;
大家谁知道比较好的线程关闭方式。
------解决方案--------------------
- Delphi(Pascal) code
var FThread: TThread; FThreadList: TObjectList; begin while FThreadList.Count > 0 do begin FThread := FThreadList.Items[0]; FThread.Terminate; FThread.Waitfor; FThread.Free; FThread.Delete(0); end; FThreadList.Free; end;
------解决方案--------------------
FThread := FThreadList.Items[0]; => FThread := TThread(FThreadList.Items[0]);