private static void Worker() { WaitHandle[] wait = new[] { FReady, FStop }; while (0 == WaitHandle.WaitAny(wait)) { HttpListenerContext context; lock (FQueue) { if (FQueue.Count > 0) { context = FQueue.Dequeue(); } else { FReady.Reset(); continue; } } try { ProcessRequest(context); } catch (Exception e) { Console.Error.WriteLine(e); } } }
private static void ContextReady(IAsyncResult ar) { try { lock (FQueue) { FQueue.Enqueue(FHTTPListener.EndGetContext(ar)); FReady.Set(); } } catch { return; } }