当某个事件触发时 小弟需要暂停一部分线程,开启一个线程 可是我不知道需要暂停的线程是否已经停止 所以需要一个查询的方法 请问有没有这样的一个函数来查询线程状态的呀? 谢谢!!没有怎么写一个呀 谢谢!小弟新手  见笑了 O(∩_∩)O~

解决方案 »

  1.   

    你用什么暂停函数?我记得用挂起线程的函数时会返回一个线程ID,你那个应该也是类似的吧,直接对这个ID进行判断就好了
      

  2.   

    http://www.xuedelphi.cn/wenzhang/yytg/2009/03/200903283210.htm
      

  3.   

    /判断线程是否释放 
    //返回值:0-已释放;1-正在运行;2-已终止但未释放; 
    //3-未建立或不存在 
    function TFrmMain.CheckThreadFreed(aThread: TThread): Byte; 
    var 
     i: DWord; 
     IsQuit: Boolean; 
    begin 
     if Assigned(aThread) then 
     begin 
       IsQuit := GetExitCodeThread(aThread.Handle, i); 
       if IsQuit then           //If the function succeeds, the return value is nonzero. 
                                     //If the function fails, the return value is zero. 
       begin 
         if i = STILL_ACTIVE then    //If the specified thread has not terminated, 
                                     //the termination status returned is STILL_ACTIVE. 
           Result := 1 
         else 
           Result := 2;              //aThread未Free,因为Tthread.Destroy中有执行语句 
       end 
       else 
         Result := 0;                //可以用GetLastError取得错误代码 
     end 
     else 
       Result := 3; 
    end;