private void OnRequestCompleted(RequestCompletedEventArgs e) { try { _requestCompletedEvent?.Invoke(this, e); } catch (Exception) { } }
private async Task ProcessRequest(HttpListenerContext context) { // Begin Process Request Scope var eventArgs = new RequestCompletedEventArgs(); bool abort = false; try { if (_OnRequest != null) { var startTime = Stopwatch.GetTimestamp(); await _OnRequest(context); eventArgs.RequestDurationTickCount = Stopwatch.GetTimestamp() - startTime; eventArgs.Url = context.Request.Url; } } catch (HttpListenerException) { abort = true; } catch (Exception e) { eventArgs.Exception = e; try { context.Response.Headers.Clear(); context.Response.ContentLength64 = 0; context.Response.StatusCode = 500; } catch (Exception) { abort = true; } } finally { try { if (abort) { context.Response.Abort(); } else { context.Response.Close(); } } catch (Exception) { } } // End Handle Request Scope OnRequestCompleted(eventArgs); }