temps execution CreateProcess
Bonjour
Je suis en train de réaliser une application graphique en visual c++ et j'ai un probleme avec la fonction CreateProcess.
Mon application graphique crée un process fils CreateProcess(....) et j'attends la fin du process avec WaitForSingleObject(....).
Avant le CreateProcess() j'ai un atexit(endProcess), endProcess() avec PostThreadMessage et TerminateProcess (au cas ou), qui gere la fin du thread pere. (Voir http://www.developpez.net/forums/viewtopic.php?t=321740 )
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
STARTUPINFO si;
PROCESS_INFORMATION pi;
void fct(){
atexit(endProcess);
//endroit je reste bloqué si l'utilisateur ferme la fenetre
CreateProcess( NULL, (LPSTR)(buffer.c_str()), NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
//arrivé ici plus de probleme
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
void endProcess{
if(pi.hProcess!=NULL){
PostThreadMessage(pi.dwThreadId, WM_CLOSE, 0, 0);
if ( GetLastError() == ERROR_INVALID_THREAD_ID ) return;// The thread is gone ... not needed to insist.
WaitForSingleObject(pi.hProcess, 2000);
if(retval == WAIT_OBJECT_0) fprintf(stderr,"[endProcess] closing process cleanly ...\n");
DWORD dwExitCode = 0;
GetExitCodeProcess(pi.hProcess, &dwExitCode);
if(dwExitCode == STILL_ACTIVE) TerminateProcess(pi.hProcess, 0);
}
} |
Il y a alors 2 cas :
- l'utilisateur (appelons le bob) ne touche a rien et l'application va jusqu'au bout : pas de pb :D
- bob ferme l'app graphique avant la fin : et la pb la fonction Createprocess() met un certain temps a s'executée donc si bob ferme l'app avant la fin du CreateProcess mon process fils ne se detruit pas et continue jusqu'a sa fin "normale".
Comment gérer ca :?:[/code]