static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host) { Debug.Assert(listenerContext != null); try { // Get the response action to take: var requestContext = new HttpRequestContext(host._hostContext, listenerContext.Request, listenerContext.User); var action = await host._handler.Execute(requestContext); if (action != null) { // Take the action and await its completion: var responseContext = new HttpRequestResponseContext(requestContext, listenerContext.Response); var task = action.Execute(responseContext); if (task != null) { await task; } } // Close the response and send it to the client: listenerContext.Response.Close(); } catch (HttpListenerException) { // Ignored. } catch (Exception ex) { // TODO: better exception handling Trace.WriteLine(ex.ToString()); } }
static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host) { Debug.Assert(listenerContext != null); try { // Get the response action to take: var requestContext = new HttpRequestContext(host._hostContext, listenerContext.Request, listenerContext.User); var action = await host._handler.Execute(requestContext); if (action != null) { // Take the action and await its completion: var responseContext = new HttpRequestResponseContext(requestContext, listenerContext.Response); var task = action.Execute(responseContext); if (task != null) await task; } // Close the response and send it to the client: listenerContext.Response.Close(); } catch (HttpListenerException) { // Ignored. } catch (Exception ex) { // TODO: better exception handling Trace.WriteLine(ex.ToString()); } }