Esempio n. 1
0
        private void RunServer()
        {
            _listener.Start();

            ThreadPool.QueueUserWorkItem(state =>
            {
                while (_listener.IsListening)
                {
                    _listener.BeginGetContext(result =>
                    {
                        var listener = result.AsyncState as HttpListener;

                        try
                        {
                            if (listener == null)
                            {
                                return;
                            }

                            var context = listener.EndGetContext(result);

                            ProcessRequest(context);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            _listenForNextRequest.Set();
                        }
                    }, _listener);

                    _listenForNextRequest.WaitOne();
                }
            });

            OnStarted.Execute();
        }