title: C# Windows 10 IoT StreamSocketListener randomly stops listening in release mode
body: <p>Ive been working on some communication between a PC and a Raspberry PI 2 with Windows 10 IoT (build 10586 TH2) using "<em>StreamSocketListener</em>". This seems to work fine in debug mode, but when testing the code in release mode the "<em>StreamSocketListener</em>" seems to randomly stop responding to requests. </p>
  
  <p>In debug mode, on the RPI2, I've had sessions with 100k requests without a single issue, but when I push the release build it stops, randomly, quite quickly (typically after a couple of hundreds requests). The request is of static type, so the input is the same every time.    </p>
  
  <p>Has anyone experienced the same issue, and is there a solution to this problem?</p>
  
  <p>The code is based on this blog post: </p>
  
  <p><a href="http://www.dzhang.com/blog/2012/09/18/a-simple-in-process-http-server-for-windows-8-metro-apps" rel="nofollow noreferrer"><strong>A simple in-process HTTP server for Windows 8 Metro apps</strong></a></p>
  
  <pre><code> private void Listen()
   {
        _listener = new StreamSocketListener();
        _listener.ConnectionReceived += (s, e) =&gt; ProcessRequestAsync(e.Socket);
        _listener.BindServiceNameAsync(requestPort.ToString());
   }
  private async void ProcessRequestAsync(StreamSocket socket)
      {
          try
          {
              // this works for text only
              StringBuilder request = new StringBuilder();
              using (IInputStream input = socket.InputStream)
              {
                  byte[] data = new byte[BufferSize];
                  IBuffer buffer = data.AsBuffer();
                  uint dataRead = BufferSize;
                  while (dataRead == BufferSize)
                  {
                      await input.ReadAsync(buffer, BufferSize, InputStreamOptions.Partial);
                      request.Append(Encoding.UTF8.GetString(data, 0, data.Length));
                      dataRead = buffer.Length;
                  }
              }
  
              using (IOutputStream output = socket.OutputStream)
              {
                  string requestMethod = request.ToString().Split('\n')[0];
                  string[] requestParts = requestMethod.Split(' ');
  
                  if (requestParts[0] == "GET")
                      await WriteResponseAsync(requestParts[1], output);
                  else
                      throw new InvalidDataException("HTTP method not supported: "
                                                     + requestParts[0]);
              }
          }
          catch (Exception e)
          {
              Debug.WriteLine("Main ex: " + e);
          }
          RequestCount++;
      }
  </code></pre>