各位大佬,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程式等待外調工具運行完并自動關閉后,不會出現卡死一段時間嗎?
uj5u.com熱心網友回復:
WaitForSingleObject 這里就是阻塞性操作最簡單的 BeginWaitCursor EndWaitCursor 包含長時間操作
如果有其它任務需求,可以考慮定時器檢測 或用后臺執行緒
uj5u.com熱心網友回復:
之所以用WaitForSingleObject 這個,是為了在外調工具結束后,將它關閉,但是外調什么時候結束并不知道,因此這個有什么好的辦法處理嗎?既可以外調工具結束后自動關閉,又可以不讓MFC程式在外調工具期間出現卡死的現象?轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/276396.html
標籤:基礎類
