Home > Software engineering >  MFC through ShellExecuteEx external tools, card to death will be a period of time
MFC through ShellExecuteEx external tools, card to death will be a period of time

Time:04-16

Dear bosses, MFC diversion tools code is as follows:

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 (& amp; ShExecInfo))
{
return 0;
}

//WaitForSingleObject (ShExecInfo hProcess, INFINITE).

If (WaitForSingleObject (ShExecInfo hProcess, dwMilliseconds)==WAIT_TIMEOUT)
{
The TerminateProcess (ShExecInfo. HProcess, 0);
return 0;
}
DWORD dwExitCode;
if (! GetExitCodeProcess (ShExecInfo hProcess, & amp; DwExitCode))
{
return 0;
}
In a button click event to other tools, will be stuck for a period of time, the problem, how should solve? Or, what better way to allow for MFC program waiting for the other tool after operation and automatically shut down, there will not be stuck for a period of time?

CodePudding user response:

The WaitForSingleObject here is obstructive operation
The simplest BeginWaitCursor EndWaitCursor contains long time operation
If there are other mission requirements, can consider the timer testing or use the background thread

CodePudding user response:

reference 1st floor zgl7903 response:
WaitForSingleObject here is obstructive operation
The simplest BeginWaitCursor EndWaitCursor contains long time operation
If there are other mission requirements, can consider the timer test or use a background thread
with the WaitForSingleObject this, for at the end of the other tools, will close it, but when external end may not know, so what's the good way to deal with? Both can external tool automatically shut down after the end, and can not let the MFC procedures, the phenomenon of the jammed during the diversion tools?
  • Related