1
Reply

C# working with a called process

dc

dc

Oct 4 2012 12:07 AM
1.1k
In a C# 2008 application, I have a foreach loop that is listed below:

for each (PkgID in PkgIDs)
  {
Process eProcess = new Process();
String Process_Arguments = null;
eProcess.StartInfo.UseShellExecute = false;
eProcess.StartInfo.FileName = strConsoleAppLocation;
Process_Arguments = filedirectorypath + " 7654" + PkgID;
eProcess.StartInfo.Arguments = Process_Arguments;
eProcess.Start();
eProcess.WaitForExit(1800);
eProcess = null;
Process_Arguments = null;
}

As you can see from the code I listed above I have the following questions:
1. For each iteration of the for loop I create a new process object
called eProcess and then I set eProcess = null; near the end of the loop.
Thus can you tell me if this is code or not and why? If you have better
code that I could use would you tell me what you recommend by pointing
me to some code I can use as a reference??
2. You can see that I also have the following line of code,
  eProcess.WaitForExit(1800);
  I have this line since the process that is being called does not seem to
complete its processing before the control is returned to this program.
Thus can you tell me the following:
a. Is the number of milliseconds that I specify a good amount? Can you tell
me why or why not?
b. Since the code is returned to this calling program before the entire
eProcess finished, can you tell me if this is a good way to wait for
the eprocess to finish? I would think there is a better way to
what for eProcess to finish. If so, is there a way to tell when the eProcess
is really finished executing?

Answers (1)