Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess you are trying to accept multiple requests on your listener. If you read your code carefully you will find you are instantiating infinite number of listeners instead of creating a single listener to handle multiple calls.</p> <p>The exception you are actually getting is a StackOverflowException (the only exception that cannot be catched with <code>try-catch</code> blocks) The application breaks no matter what you do.</p> <p>Remove your <code>while</code> loop (just call Listen once) and try using the following approach in your Listen method.</p> <pre><code>HttpListener listener = new HttpListener(); //add your prefixes here listener.Start(); AsyncCallback processRequest = delegate(IAsyncResult result) { //set the listener to listen for next request listener.BeginGetContext(processRequest, listener); HttpListenerContext context = listener.EndGetContext(result); //Your code to handle the request here } listener.BeginGetContext(processRequest, listener); </code></pre> <p>This creates the loop you are looking for with a single <code>HttpListener</code></p> <p>Hope this helps</p> <p><b>UPDATE</b>: If you uncomment the request handling code you will note that the exception does not occur since you block the thread when calling <code>listener.GetContext()</code> and the listener hangs until it receives a request and the Listen method does not return. By just calling <code>listener.Start()</code> which returns inmediatelly and then returning true you are looping at a really fast rate creating many listeners.</p> <p>Your code might work this way but it's inefficient because you have to create a listener for every request. It's better let a single listener handle all the requests asynchronously because if one of your request takes 10 seconds to execute your loop won't create another listener until you respond to the requesting client.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload