title: Program runs in background through cmd even after Process is explicitly closed
body: <p>I have a <code>Process l_batchProcess</code> and internally it executes <code>cmd.exe</code> which has certain commands related to <code>CAT.NET cmd</code>, But when I <b>explicitly</b> close the Process instance , I see that it still executes the CAT.NET cmd.exe in the background .</p>
  
  <p>There is another issue; I'm not sure if <code>l_batchProcess.WaitForExit()</code> has anything to do keep the process to get back once CAT.NET is completed in background. When I check for <code>l_batchProcess</code> it seems the process has exited and tells no process is associated. </p>
  
  <p>Could someone guide me and let me know if more details are required.
  <code>ExecuteBatchFile</code> is run asynchronously.</p>
  
  <pre><code>public string ExecuteBatchFile(BatchFile batchFile)
  {
      //var lockObject = new object();
      string returnMessage = string.Empty;
      l_batchProcess.StartInfo = new ProcessStartInfo()
      {
          FileName = batchFile.InputFilePath,
          UseShellExecute = false,
          CreateNoWindow = true,
          RedirectStandardError = true,
          RedirectStandardOutput = true,
      };
  
      if (File.Exists(batchFile.InputFilePath))
      {
          try
          {
              l_batchProcess.Refresh();
              l_batchProcess.Start();
              processStartedFlag = true;
              l_batchProcess.BeginOutputReadLine();
              l_batchProcess.BeginErrorReadLine();
              l_batchProcess.WaitForExit();
  
              if (l_batchProcess.ExitCode != 0)
                  returnMessage = "Errors while executing";
          }
          finally
          {
              CloseProcess();
          }
      }
      else
      {
          returnMessage = "Batch File path incorrect";
      }
      File.Delete(batchFile.InputFilePath);
      return returnMessage;
  }
  
  public bool CloseProcess()
  {
      if (!processStartedFlag) return false;
      l_batchProcess.CancelOutputRead();
      l_batchProcess.CancelErrorRead();
      l_batchProcess.Close();
      processStartedFlag = false;
      return true;
  }
  </code></pre>
  
  <p><b>EDIT :</b> Sorry I think from my question it appears that the process is still running in the normal course , I meant when I explicitly try to close the process.</p>