stop process


Well-known member
Nov 13, 2012
Programming Experience
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();
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;
Process_Arguments = null;
eProcess.StartInfo.UseShellExecute = false;
Process_Arguments = " 2 TIM";
eProcess.StartInfo.Arguments = Process_Arguments;
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:

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?
I also have the following additional questions to ask:

1. When I run the C# 2008 application in the debug mode and give the program the paramters required to execute the application, The program reaches the code: Environment.Exit(1);
Thus how can I debug the application to see the way it is running where it never reaches the end of the code?
2. When I look in task manager on the production server or on my workstation, I see this application as a process is still running. Is there a way that I can attach to an exsiting process on my workstation and see why the program never reaches the end? if so, how would I accomplish this goal?
3. I am assuming my problem is how the application connects and/or unconnects to the web service it calls. The program was iniitally written by the contract shop that has the web service. This contract shop that wrote their appliation in Java said they just fixed their problem that releases all the connections from their side. Would this affect me some how?
Are there other things I can be looking for to see what is causing the problem?
4. When the C# 2008 is running, I know it reaches all the code that updates the database since that part of the application works correctly.
5. Since the driver program (C# 2010) calls the C# 2008 program that does not end, I would assume that I would put the code you recommended, "if (!eProcess.HasExited) eProcess.Kill();", in the driver program correct? I can not see putting that code in the C# 2008 program since it apparently never gets to the part of the code the finish executing, correct?
Top Bottom