Context gets called one last time when you call Close, you must handle the object disposed exception that could get thrown
static void Context(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
try
{
//If we are not listening this line throws a ObjectDisposedException.
HttpListenerContext context = listener.EndGetContext(result);
context.Response.Close();
listener.BeginGetContext(Context, listener);
}
catch (ObjectDisposedException)
{
//Intentionally not doing anything with the exception.
}
}