ゞ情非得已Sky 发表于 2023-12-27 23:31:46

检测自身是否无响应

<火山程序 类型 = "通常" 版本 = 1 />

方法 检测自身是否无响应 <类型 = 逻辑型 注释 = "检测自身程序是否无响应" 返回值注释 = "返回假有响应返回真无响应" @禁止流程检查 = 真>
{
    @ int id = GetCurrentProcessId();
    @ HANDLE hProcess = ::OpenProcess (PROCESS_ALL_ACCESS,NULL,id);
    @ ::CloseHandle(hProcess);
    @ FILETIME createTime, exitTime, kernelTime, userTime;
    @ if (GetProcessTimes(hProcess, &createTime, &exitTime, &kernelTime, &userTime) == 0)
    @ {
    @ return false;
    @ }
    @ ULARGE_INTEGER processTime;
    @ processTime.LowPart = userTime.dwLowDateTime;
    @ processTime.HighPart = userTime.dwHighDateTime;
    @ ULARGE_INTEGER currentTime;
    @ GetSystemTimeAsFileTime(reinterpret_cast<LPFILETIME>(&currentTime));
    @ ULONGLONG elapsedTime = currentTime.QuadPart - processTime.QuadPart;
    @ elapsedTime /= 10000;
    @ if (elapsedTime >= 3000)
    @ {
    @ return true;
    @ }
    @ return false;

}




xrea 发表于 2023-12-27 23:41:32

?程序都无响应了,怎么调用api检测?

易入门 发表于 2023-12-28 00:45:28

xrea 发表于 2023-12-27 23:41
?程序都无响应了,怎么调用api检测?

创建线程

urenai 发表于 2023-12-28 10:56:31

<火山程序 类型 = "通常" 版本 = 1 />

方法 检测自身是否无响应 <类型 = 逻辑型 注释 = "检测自身程序是否无响应" 返回值注释 = "返回假有响应返回真无响应" @禁止流程检查 = 真>
{
    @ int id = GetCurrentProcessId();
    @ HANDLE hProcess = ::OpenProcess (PROCESS_ALL_ACCESS,NULL,id);
//   @ ::CloseHandle(hProcess);
    @ FILETIME createTime, exitTime, kernelTime, userTime;
    @ if (GetProcessTimes(hProcess, &createTime, &exitTime, &kernelTime, &userTime) == 0)
    @ {
    @ return false;
    @ }
    @ ::CloseHandle(hProcess);

    @ ULARGE_INTEGER processTime;
    @ processTime.LowPart = userTime.dwLowDateTime;
    @ processTime.HighPart = userTime.dwHighDateTime;
    @ ULARGE_INTEGER currentTime;
    @ GetSystemTimeAsFileTime(reinterpret_cast<LPFILETIME>(&currentTime));
    @ ULONGLONG elapsedTime = currentTime.QuadPart - processTime.QuadPart;
    @ elapsedTime /= 10000;
    //@ if
    //@ {
    @ return (elapsedTime >= 3000);
    //@ }
    //@ return false;

}

页: [1]
查看完整版本: 检测自身是否无响应