title: Anonymous Pipe not ending stream?
body: <p>Hello I am having a strange error with using pipes to communicate between two process. In short everything is working fine with the program except that the client side never closes the stream, meaning the server's streamReader.readLine never returns null, causing the sever process to never terminate. I'm convinced this is a simple issue but I and struggling to find a answer. Here is some relevant code:</p>
  
  <p><strong>Server Side:</strong></p>
  
  <pre><code>using (StreamReader sr = new StreamReader(clientServer))
                      {
                          // Display the read text to the console
                          string temp;
                          int count = 0;
  
                          while ((temp = sr.ReadLine()) != null)
                          {
                              if (count == 0)
                              {
                                  Console.WriteLine("==========Parent Process found text:like==========");
                              }
  
                              Console.WriteLine(temp);
                              count++;
                          }
                          Console.WriteLine("out of while loop");
  
                      }
  </code></pre>
  
  <p><strong>Client Project:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.IO.Pipes;
  
  class PipeClient
  {
  static void Main(string[] args)
  {
      try
      {
          if (args.Length &lt; 3)
          {
              Console.WriteLine("Invalid number of commandline arguments");
          }
  
          else
          {
              List&lt;string&gt; inputList = new List&lt;string&gt;();
              List&lt;string&gt; foundMatchList = new List&lt;string&gt;();
  
              using (PipeStream pipeClientIn =
                  new AnonymousPipeClientStream(PipeDirection.In, args[0]))
              {
  
                  using (StreamReader sr = new StreamReader(pipeClientIn))
                  {
                      // Display the read text to the console
                      string temp;
                      int count = 0;
                      while ((temp = sr.ReadLine()) != null)
                      {
                          if (count == 0)
                          {
  
                              Console.WriteLine("==========Client Process Read Text:==========");
                          }
                          Console.WriteLine(temp);
                          inputList.Add(temp);
                          count++;
                      }
                      foreach (var curtString in inputList)
                      {
                          if (curtString.Contains(args[2]))
                          {
                              foundMatchList.Add(curtString);
  
                          }
                      }
                  }
                  //Console.WriteLine("released sr");
              }
              // Console.WriteLine("released pipeClientIn");
              using (PipeStream pipeClientOut =
                  new AnonymousPipeClientStream(PipeDirection.Out, args[1]))
              {
                  using (StreamWriter sw = new StreamWriter(pipeClientOut))
                  {
  
                      sw.AutoFlush = true;
                      foreach (var match in foundMatchList)
                      {
  
                          sw.WriteLine(match);
  
                      }
  
                  }
  
  
              }
              //Console.WriteLine("released pipeClientOut");
  
          }
  
  
      }
      catch (Exception e)
      {
          /* if (args.Length == 0)
              Console.WriteLine("no arguments");
          foreach(String s in args)
          {
              Console.Write("{0} ", s);
          }*/
          Console.WriteLine(e.Message);
      }
  
  
  }
  }
  </code></pre>
  
  <p>I've tested and can confirm that the client process terminates.
  I attempted to manually flush and close the Client StreamWriter but this did not work.
  My overall question is: Why am I never seeing the the "out of while loop" message? And how can fix my client so that it will end the stream?</p>