dc

dc

  • NA
  • 663
  • 0

work with a C# process

Feb 16 2013 5:20 AM
I am having a problem with a C# 20008 windows application not finishing executing and I am trying to determine how to resolve  the issue. Initally a C# 2010 console application was written to call a C# 2008 console application Which in turn calls a web
service. I changed both of these applications to be windows application since I did not want the dos pop up windows.
  The problem is the called C# 2008 windows application never finsishes executing. The process stays in memory.  The code listed below is part of the code from the C# 2010 application.
 
  private static Logger logger = LogManager.GetCurrentClassLogger();
  try
  {
  Process eProcess = new Process();
  strConsoleAppLocation = ConfigurationManager.AppSettings["client_location"];
  String Process_Arguments = null;
  eRPT_Process.StartInfo.UseShellExecute = false;
  eRPT_Process.StartInfo.FileName = strConsoleAppLocation;
  Process_Arguments = " 1 CLI";
  eProcess.StartInfo.Arguments = Process_Arguments;
  eProcess.Start();
  eProcess.WaitForExit(1800);
  Process_Arguments = null;
  eProcess.StartInfo.UseShellExecute = false;
  Process_Arguments = " 2 TIM";
  eProcess.StartInfo.Arguments = Process_Arguments;
  eProcess.Start();
  eProcess.WaitForExit(1800);
  eProcess.Dispose();
  Process_Arguments = null;
  }
  catch (Exception e)
  {
  logger.Error(e.Message + "\n" + e.StackTrace);
  } 
 
  I know that C# 2008 app never finishes by looking at processes in memory. In addition if I change the line of code to  the following: eProcess.WaitForExit();, the application never returns to the called program.

  In the C# 2008 called application, the last line of code that is executed is the following:  Environment.Exit(1); 
  Thus to resolve this problem, I have the following questions:
  1. If you have recommendations on how I can change the code I listed above, would you let me know what  your recommendations are?
  2. Since these 2 programs are in production right now, I am wondering if you have suggestions on how I can resolve this problem for a 'bandaid' fix? Is there a way that I can just stop the C# 2008 process that is running when  the C# 2010 program finishes executing? Is there a way to make the C# 2008 application kill its own process when it
  has finished executing? If so, can you show me code on how to solve this problem?
  3. For the long term fix, can you tell me how to determine why the C# 2008 process does not stop and how I can fix it?  I would use profiler, however my company only has the professional version of visual studio 2010.  thus can you tell me what your recommendations are?

Answers (3)