Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# process code

C# process code

Scheduled Pinned Locked Moved C#
csharpdatabasetutorialquestioncareer
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sc steinhayse
    wrote on last edited by
    #1

    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();
                 } 
    

    :wtf: 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?

    D 1 Reply Last reply
    0
    • S sc steinhayse

      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();
                   } 
      

      :wtf: 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?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Did you happen to read the documentation on the ProcessClass?? There's a little property called "ExitCode" which will contain the exit code of the process once it terminates. You don't need to call Close. It'll be called by the Process class Dispose method automatically, which you SHOULD be calling when you're done with the Process object. You might want to wrap that process code in a using block to take care of this for you.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups