紧急救助:关于线程的终止!
我写的一个的线程TMyThread(从TThread继承)。它的执行体如下:
try
IdClient.Connect;
{.............................
//循环读取直到Terminated
并对读取的内容做分析处理
............................}
while IdClient.Connected do
begin
if Terminated then Break;
try
Command:=IdClient.ReadLn('',500);
Except
//Do Something!
Exit;
end;
//DO Something About command;
end;
finally
if IdClient<> nil then
begin
if IdClient.Connected then
begin
IdClient.Disconnect;
end;
IdClient.Free;
IdClient:=nil;
end;
end;
其中的IdClient是在线程创建时创建的一个TIdTCPClient的实例!
然后我在外部创建了一个线程实例m_thread;
在销毁这个线程时,我写了:
m_thread.Resume;
m_thread.Terminate;
Sleep(1000);
m_thread.waitfor;
m_thread.free;
m_thread:=nil;
但是执行到m_thread.waitfor的时候就停了,一直等待着线程的终止。
请问有什么好的办法销毁这个线程?
用TerminateThread? 该这么用?
谢谢