MFC通过ShellExecuteEx外调工具,会一段时间卡死无反应
lwei2 2021-04-15 06:19:36 各位大佬,MFC外调工具的代码如下:
SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = _T("runas");
ShExecInfo.lpFile = lpszAppPath;
ShExecInfo.lpParameters = lpParameters;
ShExecInfo.lpDirectory = lpszDirectory;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
if (!ShellExecuteEx(&ShExecInfo))
{
return 0;
}
//WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
if (WaitForSingleObject(ShExecInfo.hProcess, dwMilliseconds) == WAIT_TIMEOUT)
{
TerminateProcess(ShExecInfo.hProcess, 0);
return 0;
}
DWORD dwExitCode;
if (!GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode))
{
return 0;
}
在一个按钮的点击事件去外调工具,会出现卡死一段时间,这个问题,要怎么解决?或者,有什么更好的办法使得使得MFC程序等待外调工具运行完并自动关闭后,不会出现卡死一段时间吗?