title: C# socket StreamReader.ReadToEnd wait forever
body: <p>In an Universal Windows Platform (UWP) app, I'm trying to send an object to a Windows form program using socket:</p>
  
  <pre><code>public void CreateListener()
      {
          TcpListener listener = new TcpListener(IPAddress.Any, port);
          listener.Start();
  
          while (true)
          {
              if (listener.Pending())
              {
                  var childSocketThread = new Thread(() =&gt;
                  {
                      string data = null;
                      var Client = listener.AcceptTcpClient();
                      using (NetworkStream ns = Client.GetStream())
                      using (StreamReader sr = new StreamReader(ns))
                      {
                          data = sr.ReadToEnd();
                          var Items = JsonConvert.DeserializeObject&lt;Models.Orders&gt;(data);
                          Process(Items);
                          ns.Flush();
                          ns.Close();
                      }
                  });
                  childSocketThread.IsBackground = true;
                  childSocketThread.Start();
              }
              else
              {
                  Thread.Sleep(50); //&lt;--- timeout
              }
          }
      }
  </code></pre>
  
  <p>But receiving object stuck in <code>ReadToEnd</code> and never exit.
  What should I do?</p>