1
Reply

C# 2010 excuting a process

dc

dc

Oct 21 2012 1:27 PM
972
I have the following questions about a C# 2010 application calling another C# console application using the C# process method:
1. When using a process method, I have seen where you can use the process as either a static method call and also an object that can be instantiated. What is the preferred method and why?
2. If I instantiate a process as an object, do I need to delete that process in memory so that it does not stay around in memory? If so, how do you delete the process?
3. The following code is a snippet of what I have setup so far. Can you tell me if you see any problems with this code? If so can you tell me how to modify the code so that it works better?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.ComponentModel;

namespace eScripts
{
  class Run_e
  {
 private static String strConsoleAppLocation = "C:\\Program Files (x86)\\coname\\1.exe";
  private static String strWebServiceurl = "https://etest//WebService1";
 static void Main(string[] args)
  {
  Process eProcess = new Process();
  try
  {
  String Process_Arguments = null;
  eProcess.StartInfo.UseShellExecute = false;
  eProcess.StartInfo.FileName = strConsoleAppLocation;
  Process_Arguments = strWebServiceurl + " 164 " + cust1";
  eProcess.StartInfo.Arguments = Process_Arguments;
  eProcess.Start();
  eRPT_Process.WaitForExit(1800);
  Process_Arguments = null;
  eDataContext rptData = new eDataContext();
  string[] PkgIDs = rData.Trackings.Where(c => c.Received_Date != null
  .Select(c => c.Package_ID).ToArray();
  foreach (string PkgID in PkgIDs)
  {
  String Process1_Arguments = null;
  Process Process1 = new Process();
  Process1.StartInfo.FileName = strConsoleAppLocation;
  Process1_Arguments = strWebServiceurl + " 10 " + PkgID;
  Process1.StartInfo.Arguments = Process1_Arguments;
  Process1.Start();
  Process1.WaitForExit(1800);
  Process1.Dispose();
  Process1_Arguments = null;
  }
 ateTime StartDateTime = rData.Trackings.Where(c => c.Error_Report_Date != null).Select(c => c.Error_Report_Date).Max().GetValueOrDefault();
  DateTime CurDateTime = DateTime.Now;
  string[] AddPkgIDs = (from rData.Trackings.where(c.tNumber.Substring(0, 3) == "dis"
  select TNumb).Distinct().ToArray();
  if (AddPkgIDs != null)
  {
  foreach (string AddPkgID in AddPkgIDs)
  {
  String Process4_Arguments = null;
  Process Process4 = new Process();
  Process4.StartInfo.FileName = strConsoleAppLocation;
  Process4_Arguments = strWebServiceurl + " 14295 " + AddPkgID;
  Process4.StartInfo.Arguments = Process4_Arguments;
  Process4.Start();
  Process4.WaitForExit(1800); //waits 2 minutes 
  Process4.Dispose();
  }
  }
  }
 
  catch (Exception e)
  {
  Console.WriteLine(e.Message);
  }
  }
  }

Answers (1)