Re: Problem with termination of a console app within an MFC app while console is working
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 13:18:04 -0500
Generally, doing a WaitForSingleObject on the child process is a Really Bad Idea, because
it locks up your GUI thread.
You will need to signal your console app. Look at SetConsoleCtrlHandler and
GenerateConsoleCtrlEvent to notify the child process that it should terminate. Also use
the CREATE_NEW_PROCESS_GROUP flag for CreateProcess, as described in
GenerateConsoleCtrlEvent.
joe
On 23 Jan 2006 12:52:09 -0800, "Bulent" <hatipoglu.bulent@xxxxxxxxx> wrote:
>Hi,
>
>I have a mfc application. It executes a console application with
>CreateProcess which is a lenghtly process. I will hide the console app
>from the user.
>
>My problem is this: I want to close MFC app AND console application
>While hidden console app. is still active. How can I do this?
>
>Code is below:
>void CCPSDoc::OnAnalyseRun()
>{
> // TODO: Add your command handler code here
> CString str ;
>
> str = "cmd /c waitdlg.exe" ; //an app can work 15 minutes
>
> STARTUPINFO si;
> PROCESS_INFORMATION pi;
> ZeroMemory( &si, sizeof(si) );
> si.cb = sizeof(si);
>
>
>
> si.dwFlags = STARTF_USESHOWWINDOW ;
> si.wShowWindow = SW_HIDE ;
>
> ZeroMemory( &pi, sizeof(pi) );
> CWaitCursor wait ;
> //// Start the child process.
>
> if( ! CreateProcess( NULL, // No module name (use command line).
> (LPSTR)(LPCSTR) str ,// Command line.
> NULL, // Process handle not inheritable.
> NULL, // Thread handle not inheritable.
> FALSE, // Set handle inheritance to FALSE.
> 0, // No creation flags.
> NULL, // Use parent's environment block.
> NULL, // Use parent's starting directory.
> &si, // Pointer to STARTUPINFO structure.
> &pi ) // Pointer to PROCESS_INFORMATION structure.
> )
> {
> AfxMessageBox( "CreateProcess failed." );
> }
>
>
> //WaitForSingleObject( pi.hProcess, INFINITE )
> wait.Restore() ;
>
> ////Close process and thread handles.
> CloseHandle( pi.hProcess );
> CloseHandle( pi.hThread );
>
>}
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Prev by Date: Direct3D and ATL window
- Next by Date: Re: the process of debugging
- Previous by thread: Re: Problem with termination of a console app within an MFC app while console is working
- Next by thread: Re: Overloading () in MC++
- Index(es):
Relevant Pages
|
|