- Miguel Alzate
- PowerBuilder
- Friday, 29 March 2019 11:50 AM UTC
Hi.
I'm new to C# programming. I need to asynchronously (from a Web service) run a number of instances of the same process and, then, check if they have all finished. For this, I use a C# process array. Could anyone please tell me if the following code is be correct (conditional compilation in bold)?
string ls_exe="c:\payroll.exe" //Process to be executed
string ls_parm //Command line argument of the process
integer li_n=5 //Number of instances of the process to be executed (actually an unknown and not fixed value)
integer li_proc //Number of executed instances of the process
integer li_done //Number of terminated instances of the process
integer li_k //For iteration
//Declare unbounded array of processes
#if defined pbwebservice then
system.diagnostics.process proc[]
#end if
//Assign and execute the array of processes
do while true
//For...Next not used because number of instances is actually unknown
li_k ++
ls_parm = string(li_k)
#if defined pbwebservice then
proc[li_k] = system.diagnostics.process.start(ls_exe, ls_parm)
#end if
li_n then exit //No more instances to execute
loop
//Check for termination of all process instances in the array
#if defined pbwebservice then
li_proc = proc.getupperbound(0) //Number of executed process instances
#end if
do while true //Scan continually the array to check termination
for li_k = 0 to li_proc
#if defined pbwebservice then
if proc[li_k].hasexited then li_done ++ //Increase count of terminated instances
#end if
next
if li_done = li_proc then exit //Number of terminated instances equals the number of executed instances
loop
//Display termination message
#if defined pbwebservice then
console.writeline("All process instances have been terminated")
#end if
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.