title: C# Windows service - zombie process after stopping
body: <p>I'm write Windows Service on C# (.NET Framework 4.5).
  After stopping the service him process becomes a zombie-process (He don't kill by "taskkill"). </p>
  
  <p><a href="https://i.stack.imgur.com/WkjuK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WkjuK.jpg" alt="enter image description here"></a></p>
  
  <p>It ends in about 3-15 minutes: The longer the service works, the longer the process finished. In debug service correct ending and exit from all visible code.</p>
  
  <p>In work I'm execute remote commands by SSH. 
  I noticed that the execution such teams - perhaps the reason zombies.
  Because after work without having to run the commands, the process is terminated immediately.</p>
  
  <p>For execute SSH-commands I'n use SSH.NET (<a href="http://sshnet.codeplex.com/" rel="nofollow noreferrer">http://sshnet.codeplex.com/</a>):</p>
  
  <pre><code>public class RenciSSHExecute:ISSHExecutable 
  {
      public string Execute(String host, String user, String password, String command)
      {
          string result = String.Empty;
          Guid guid = Guid.NewGuid();
          try
          {
              using (var client = new Renci.SshNet.SshClient(host, user, password))
              {
                  client.Connect();
                  Logger.Information("Send SSH command [{0}]: {1}.", guid.ToString(), command);
                  var cmd = client.RunCommand(command);
                  result = cmd.Result.Replace("\n", "");
                  Logger.Information("Result SSH command [{0}]: {1}", guid.ToString(), result);
              }
          }
          catch (Exception e)
          {
              throw new Exception(String.Format("Failed execution ssh-command: {0} on {1}@{2}. Error message: {2}",
                  command, user, host, e.Message));
          }      
  
          return result;
      }
  }
  </code></pre>
  
  <p>What is the cause of zombies and how to fix it?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I use <strong>"Windows Resource Monitor"</strong>:
  <a href="https://i.stack.imgur.com/yDdzH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yDdzH.jpg" alt="enter image description here"></a>
  In the section "Assotsiated Handles" I found rows:</p>
  
  <pre><code>\Device\Mup\$COMPUTERNAME\PIPE\winreg
  </code></pre>
  
  <p>And these are the <strong>$COMPUTERNAME</strong> already disconnected machines, which the interaction is completed. </p>
  
  <p>What are these lines? Could this be the cause of zombie-process?</p>
  
  <p>In code of service I use Process.GetProcesses for getting list of running process on remote mashine:</p>
  
  <pre><code>var remoteProcesses = Process.GetProcesses(remote_client_name);
  </code></pre>
  
  <p>Could <strong>Process.GetProcesses</strong> leave some resources not closed if the machine is switched off?</p>