delphi判斷線程狀態函數(使用GetExitCodeThread API函數去判斷線程的句柄)


//判斷線程是否釋放
//返回值:0-已釋放;1-正在運行;2-已終止但未釋放;
//3-未建立或不存在

function 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;

 

http://www.cnblogs.com/azhqiang/p/3955490.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM