title: HttpListeners and ports
body: <p>I am creating an HttpListener by attempting to grab a random port that is open (or one that is not in IpGlobalProperties.GetActiveTcpConnections()). The issue I am running into is that after a while of making these connections and disposing them I am getting this error : <code>No more memory is available for security information updates</code>
  Is there any way to resolve this or is there a proper way of getting rid of HttpListeners. I am just calling listener.Close().</p>
  
  <p>Here is the method used to create the listeners :
  <pre><code>
  private HttpListener CreateListener()
          {
              HttpListener httpListener;
              DateTime timeout = DateTime.Now.AddSeconds(30);
              bool foundPort = false;
              do
              {
                  httpListener = new HttpListener();
                  Port = GetAvailablePort();
                  string uriPref = string.Format("http://{0}:{1}/", Environment.MachineName.ToLower(), Port);
                  httpListener.Prefixes.Add(uriPref);
                  try
                  {
                      httpListener.Start();
                      foundPort = true;
                      break;
                  }
                  catch
                  {
                      httpListener.Close();
                      FailedPorts.Add(Port);
                  }
              } while (DateTime.Now &lt; timeout);</p>
  
  <pre><code>        if (!foundPort)
              throw new NoAvailablePortException();
  
          return httpListener;
      }
  </code></pre>
  
  <p></pre></code></p>