المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# process code



C# Programming
09-07-2012, 04:10 AM
I have questions to ask about the following C# 2008/2010 code listed below:
Process eProcess = new Process(); eDataContext rData = new eDataContext(); string[] PkgIDs = rData.Trans.Select(c => c.Package_ID ).ToArray(); foreach (string PkgID in PkgIDs) { eProcess.StartInfo.FileName = "app1.exe"; eProcess.StartInfo.Arguments = "10 " + " 5" + PkgID; eProcess.Start(); eProcess.WaitForExit(); eProcess.Close(); } http://www.barakasoft.com/script/Forums/Images/smiley_WTF.gif
My questions are the following:
1. After the
eProcess.WaitForExit();
line of code is finished waiting for the process to finish executing, is there a way to check for the condition code returned from the run. I basically want to see if the job that executed ran successfully.
If so, can you tell me how to setup that code?
2. Do I need the line of code
"eProcess.Close();" Why or why not?
3. I am basically looping thoough calls executing a process based upon values received in PkgID that is stored in a database table. Is this code good or not? Can you tell me why or why not? If the code is not good, can you tell me a better way to
write the code?