CreateProcess Loop Problem (Visual C++ 2005)
When I call the method perform_single_upload() in this loop:
----------------------------
private: System::Void start_uploads(int i)
{
i = 0;
while(i < master_list->Length)
{
//Create a single batch file containing the upload instructions
create_single_upload(i);
//Increment loading bar
pb_Progress->Value::set(pb_Progress->Value::get() + 1);
//Load and perform the batch file contents
perform_single_upload();
//Increment loading bar
pb_Progress->Value::set(pb_Progress->Value::get() + 1);
//Delete the batch file in preparation for the next one
cleanup_upload();
//Increment loading bar
pb_Progress->Value::set(pb_Progress->Value::get() + 1);
i++;
}
}
----------------------------
With perform_single_upload() doing the following:
----------------------------
STARTUPINFO si;
PROCESS_INFORMATION pi;
LPTSTR szCmdline=_tcsdup(TEXT("upload.bat"));
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
szCmdline, // 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
)
{
//Something went wrong.
AnError^ uploaderror = gcnew AnError();
uploaderror->label1->Text::set("There was an error finding a batch
script file.");
uploaderror->ShowDialog();
return;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
----------------------------
....my main process appears frozen until the loop in the first method
has gone through all of its iterations. I can't seem to figure out
why it doesn't update anything after calling the
perform_single_upload() method for the first time.
Is there any way to maintain control of my main application after a
CreateProcess(), or system(), or WinExec(), etc. call?