I am in the process of writing a service that is similar to UNIX cron.
I need to be able to run multiple processes simultaneously. The code below always waits for one process to finish before continuing. Can someone point me in the right direction to allow the program to continue without waiting. Basically, allow processes to run in the background.

Thanks.


while (ServiceStatus.dwCurrentState ==
SERVICE_RUNNING)
{
for(i=0; i<lines; i++)
{
if(check_time(i) == 1)
{
execute_process(i);

}
}

}
ServiceStatus.dwCurrentState =
SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = -1;
SetServiceStatus(hStatus,
&ServiceStatus);
LogMsg("MyCron stopped.");
return;



int execute_process(int i)
{
char command[64];

STARTUPINFO si;
PROCESS_INFORMATION pi;

strcpy(command,cron_array[i].proc);

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

// Start the child process.
if( !CreateProcess( NULL, command, NULL,
NULL, FALSE, 0, NULL, NULL, &si, &pi )
)
{
_ErrorExit( "CreateProcess failed." );
}

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );


return 0;
}