Re: CreateProcess() it's extermely slow
<luca.devoti@gmail.com> wrote in message
news:1186160067.766027.294520@q75g2000hsh.googlegroups.com...
hi all,
I want to create a program that opens all the type of documents
registered on a machine, and the easiest way to do that is to run the
CMD.EXE's START command.
I notice that if my application has no Window, the CreateProcess is
extremely fast as I want. But if I previously create a window (via
CreateWindow()) to run the same command (c:\windows
\system32\cmd.exe /
c start www.google.com) it takes something like 30 secs and it is
hard
to tell what the system is doing.
< SNIP >
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
argv[1], // 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.
)
{
result=GetLastError();
/* ZeroMemory( &lpszMess, sizeof(lpszMess) ); */
sprintf(lpszMess,"Errore:%d", result);
MessageBox(NULL,lpszMess, NULL, MB_OK);
return result;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
if ( argc==3 && !strcmp(argv[2], "debug"))
MessageBox(NULL,"Finito", NULL, MB_OK);
return 0;
}
Please be careful when cross-posting.
As I mentioned over at comp.os.ms-windows.programmer.win32, right after
calling CreateProcess(), you call WaitForSingleObject() which freezes the
main GUI thread until after the just-launched process terminates.
So, you are probably getting the same behavior in both instances (i.e.,
whether the window is or is not created), but simply don't notice it without
the window.
Mike