private void Worker() { WaitHandle[] wait = { _readyEvent.WaitHandle, StopEvent.WaitHandle }; while (0 == WaitHandle.WaitAny(wait)) { try { HttpListenerContext context; if (!_queue.TryDequeue(out context)) { _readyEvent.Reset(); continue; } if (!SecurityOn || SecMan.HandleRequest(context.Request)) { Process(context); } } catch (Exception ex) { if (ThrowExceptions) { throw; } Logger.Log(ex); } } }
protected override void ProcessContext(HttpListenerContext context) { Task.Run(() => { if (!SecurityOn || SecMan.HandleRequest(context.Request)) { Process(context); } }); }