title: How can I create an HttpListener class on a random port in C#?
body: <p>I would like to create an application that serves web pages internally and can be run in multiple instances on the same machine.  To do so, I would like to create an <code>HttpListener</code> that listens on a port that is:</p>
  
  <ol>
  <li>Randomly selected </li>
  <li>Currently unused</li>
  </ol>
  
  <p>Essentially, what I would like is something like:</p>
  
  <pre><code>mListener = new HttpListener();
  mListener.Prefixes.Add("http://*:0/");
  mListener.Start();
  selectedPort = mListener.Port;
  </code></pre>
  
  <p>How can I accomplish this?</p>