NT下的一个函数
function GetThreadTimes(hThread:THandle;var lpCreationTime,lpExitTime,
lpKernelTime,lpUserTime:TFileTime):Bool;StdCall
可以获得一个线程的运行时间,,
我没试过,呵呵,,
那位试出来了请告诉我哦。。 [email protected]
lpCreateTime 线程创建时间
LPEXITTIME 线程退出时间
LPKERNELTIME 执行操作系统代码所用时间
LPUSERTIME 执行本应用程序本身代码所用的时间以上都为Tfiletime
可以将四个参数showmessage出来吗?

解决方案 »

  1.   

    var
    lpCreateTime:TFileTime;
    LPEXITTIME:TFileTime;
    LPKERNELTIME:TFileTime;
    LPUSERTIME:TFileTime;
    begin
    GetThreadTimes(GetCurrentThreadId, lpCreateTime,lpEXITTIME,
    lpKernelTime,lpusertime);
    Memo1.Lines.Add(IntToStr(INT64(lpCreateTime)));
    Memo1.Lines.Add(IntToStr(INT64(lpEXITTIME)));
    Memo1.Lines.Add(IntToStr(INT64(lpKernelTime)));
    Memo1.Lines.Add(IntToStr(INT64(lpusertime)));
    如果没有溢出的话。//Delphi没有QWORD-_-
    MSDN的话:
    Res
    All times are expressed using FILETIME data structures. Such a structure contains two 32-bit values that combine to form a 64-bit count of 100-nanosecond time units.Thread creation and exit times are points in time expressed as the amount of time that has elapsed since midnight on January 1, 1601 at Greenwich, England. There are several functions that an application can use to convert such values to more generally useful forms; see Time Functions.Thread kernel mode and user mode times are amounts of time. For example, if a thread has spent one second in kernel mode, this function will fill the FILETIME structure specified by lpKernelTime with a 64-bit value of ten million. That is the number of 100-nanosecond units in one second.
      

  2.   

    如果我要查看查询需要的时间怎么做。用OpenThread指定的是什么?
      

  3.   

    我转换得到的时间都是0
    function FileTimeToDateTime(FileTime: TFileTime): TDateTime;
    var
      SysTime: TSystemTime;
    begin
      if not FileTimeToSystemTime(FileTime, SysTime) then
        raise Exception.CreateFmt('FileTimeToSystemTime failed. ' +
          'Error code %d', [GetLastError]);
      with SysTime do
        Result := EncodeDate(SysTime.wYear, SysTime.wMonth, SysTime.wDay) +
          EncodeTime(SysTime.wHour, SysTime.wMinute, SysTime.wSecond, SysTime.wMilliseconds);
    end;