title: Detect WinRM connection loss
body: <p>I connect to a remote PC via WinRM using C#.</p>
  
  <p>I would like to be able to detect as fast as possible if the connection is lost (but not correctly closed by the remote, for example the power of the PC was shut or the Ethernet cable is disconnected).
  I would like to detect a connection loss in less than 5 seconds. Is that possible?</p>
  
  <p>For information, I use this connection to run some PowerShell commands that can last a few minutes. Optimally, I would like to detect connection loss whether I am in the middle of one of these commands or not.</p>
  
  <p>My C# code is:</p>
  
  <pre><code>WSManConnectionInfo connectionInfo = new WSManConnectionInfo(true, ipAddress, 5986, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", accountCredential);
  connectionInfo.SkipCACheck = true; // SkipCACheck allows to connect without installing the certificate on the host.
  connectionInfo.SkipCNCheck = true; // SkipCNCheck allows server name to not match certificate.
  connectionInfo.OpenTimeout = 3000; // 3s
  connectionInfo.OperationTimeout = 300000; // 5min
  connectionInfo.IdleTimeout = 7200000; // 2h
  runspace = RunspaceFactory.CreateRunspace(connectionInfo);
  </code></pre>