none
C# program call another C# program RRS feed

  • Question

  •    I am having a C# 2010 windows application call another C#  2008 windows application with the following  code:          
      String Process_Arguments = null;
    eRPT_Process.StartInfo.UseShellExecute =  false;
    eRPT_Process.StartInfo.FileName = strConsoleAppLocation;
      Process_Arguments = strEncryptedValue + " " + strWebServiceurl + " 1  try";
    eRPT_Process.StartInfo.Arguments = Process_Arguments;
      eRPT_Process.Start();
    eRPT_Process.WaitForExit(1800);
    Process_Arguments =  null;

    My question is the following line of  code:
    eRPT_Process.WaitForExit(1800);

    If this program does not wait  for the other program to finish executing, could this make the second program  stay in memory for awhile?

    Basically the first program calls the second  program in a loop. Thus could a thread from the previous call to the second  program be running at the same time that another call to the second program is  running? If so, could these cause the second program to have a memory  leak?
    if so how would you solve this problem?
    Thursday, February 7, 2013 10:13 PM

Answers

  • If you're worried that if the first process dies, that there will be nothing to kill off the second process, it could be considered a resource leak, but it does not match the definition of a memory leak.

    A memory leak is when a process has allocated memory, lost track of the fact that the memory was allocated, and now the only way to free up that memory is to kill the process. That's not what's going on here. 

    Friday, February 8, 2013 8:11 PM

All replies

  • In short:

     Thus could a thread from the previous call to the second  program be running at the same time that another call to the second program is  running?

    1) Yes.  I do not have enough information to say definitively if this is happening in your case, but it sounds plausible.

    If so, could these cause the second program to have a memory  leak?
    if so how would you solve this problem?

    2) Not necessarily.  Memory leaks can and do happen but their causes can be many things.

    In general, there are a number of ways to synchronize processes.  The first thing that comes to mind is a semaphore.   If you create a named semaphore, difference processes can act on them.

    "Named system semaphores are visible throughout the operating system, and can be used to synchronize the activities of processes. You can create multiple Semaphore objects that represent the same named system semaphore, and you can use theOpenExisting method to open an existing named system semaphore."

    Another option, you could also use inter-process communications with named pipes or TCP.  

    Matt


    • Edited by tatman blue Thursday, February 7, 2013 10:26 PM
    • Proposed as answer by Naomi N Thursday, February 7, 2013 10:48 PM
    Thursday, February 7, 2013 10:25 PM
  • When the second program launches it's completely independent of the first program. It's a separate process. The first program can launch the second one and completely forget about the second ones existence. The first program can exit and the second one will still be running, and it wouldn't be considered a memory leak.

    If you only want one of the second programs to be running at a time, from the first process, I would use Interlocked.CompareExchange and have a global variable name numberOfSecondProgramsRunning. Using Interlocked.CompareExchange you can check to see one is already running, and if so, behave accordingly.

    Friday, February 8, 2013 12:09 AM
  • Could this situation be a memory leak?
    Friday, February 8, 2013 6:04 AM
  • Technically the second process will be using memory on the computer, but by any definition of an actual usage of the term 'memory leak': no.
    Friday, February 8, 2013 6:27 AM
  • Could this be an actual memory leak on the computer itself? I mean could this actually access registry keys as a memory leak?
    Friday, February 8, 2013 2:55 PM
  • If you're worried that if the first process dies, that there will be nothing to kill off the second process, it could be considered a resource leak, but it does not match the definition of a memory leak.

    A memory leak is when a process has allocated memory, lost track of the fact that the memory was allocated, and now the only way to free up that memory is to kill the process. That's not what's going on here. 

    Friday, February 8, 2013 8:11 PM