I am currently writing a program that will run mulitple programs in groups all at once and others on their own.
if( WAIT_FAILED == WaitForMultipleObjects(numberOfProgramsRan, &information[i].hProcess, TRUE, INFINITE) ) {
wcerr << L"Failure waiting for process" << endl;
}
numberOfProgramsRan is the number of programs that i ran in my loop.
&information[i] is a vector holding my process information from the create process
When i create the process in a for loop my program will wait if there are two or less processes being created (so two programs being passed in to run) before it runs my next processes.
If create more than two processes (or pass in more than two programs in my vector) my WaitForMultipleObjects it fails.
If i need to futher explain my issue please let me know.
Thanks for your help
If you only wait on a single process (index i) you should use WaitForSingleObject. If you’re waiting on multiple processes you need to pass in an array of handles as others have said – not a pointer into PROCESS_INFORMATION.
If you insist on using WaitFoRmultipleObjects for a single object use:
If you use anything other than 1 then look at the definition of PROCESS_INFORMATION:
The following dwProcessId and dwThreadID will then be incorrectly treated as handles your call will not work as expected.
Something like:
Will wait on all your processes.