title: Check remote PowerShell session status in C#
body: <p>I create PowerShell Remoting session per the following code:</p>
  
  <pre><code>AuthenticationMechanism auth = AuthenticationMechanism.Negotiate;
  
  WSManConnectionInfo ci = new WSManConnectionInfo(
      false,
      sRemote,
      5985,
      @"/wsman",
      @"http://schemas.microsoft.com/powershell/Microsoft.PowerShell";,
      creds);
  ci.AuthenticationMechanism = auth;
  
  Runspace runspace = RunspaceFactory.CreateRunspace(ci);
  runspace.Open();
  PowerShell psh = PowerShell.Create();
  psh.Runspace = runspace;
  </code></pre>
  
  <p>I have two questions, based on this code snippet:</p>
  
  <ol>
  <li>I need to run this session over a long time; hence I need to make sure that remote session is alive. How can I do this?</li>
  <li>Can I change the duration for which session should be kept alive?</li>
  </ol>