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
if li_k > 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
If you are not using the obsolete .NET Web service target in PB 2017 or older, then conditional code blocks are supported. However, I would advise against using the obsolete .NET Web service target for any new project because this is no longer being enhanced by Appeon. Also, it is legacy SOAP/XML interface rather than REST/JSON interface.
If you are existing PB 2017 customer you can try out the C# Web API in the beta version of PB 2019, and the final release is scheduled for May 31, 2019.