如题,procedure TForm1.btn1Click(Sender: TObject);
var trdHandle:THandle;
begin
 trdHandle:=CreateThread(nil,0,@ServerReader,@sockSrv,0,acThreadID);
 if trdHandle=(?) then
 begin
   dosomething;//我想在线程退出的时候做一些事。
 end;
end;

解决方案 »

  1.   

    CreateThread返回的是线程ID,和退不退出无关可以用WaitForSingleObject(trdHandle)的返回值判断线程状态
      

  2.   

    是线程ID?那么acThreadID表示的不是线程ID吗?
    WaitForSingleObject(trdHandle)怎么用,它的返回值为多少表示线程退出了。
      

  3.   

    纠正一下,是线程句柄,WaitForSingleObject的用法可以看一下API的帮助DWORD WaitForSingleObject(    HANDLE hHandle, // handle of object to wait for 
        DWORD dwMilliseconds  // time-out interval in milliseconds  
       );Return ValuesIf the function succeeds, the return value indicates the event that caused the function to return.
    If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError. 
    The return value on success is one of the following values: Value Meaning
    WAIT_ABANDONED The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
    WAIT_OBJECT_0 The state of the specified object is signaled.
    WAIT_TIMEOUT
      

  4.   

     线程状态用: GetExitCodeThread  去判断.
      

  5.   

    http://ys-f.ys168.com/?testp.zip_50chkt1e0dks7bkt1biitmln0cr5bsq0c0b5btmljtm5bu22f05f12z