title: C# Named Pipes, how to detect a client disconnecting
body: <p>My current named pipe implementation reads like this:</p>
  
  <pre><code>while (true)
  {
    byte[] data = new byte[256];                        
    int amount = pipe.Read(data, 0, data.Length);
    if (amount &lt;= 0)
    {
        // i was expecting it to go here when a client disconnects but it doesnt
       break;
    }
    // do relevant stuff with the data
  }
  </code></pre>
  
  <p>how can I correctly detect when a client disconnects?</p>