Ejemplo n.º 1
0
    public void DispatcherThread()
    {
        while (!_serviceRunning)
        {
            try
            {
                _listener = new HttpListener();
                _listener.Prefixes.Add(string.Format("http://*:{0}/", _localPort));
                _listener.Start();
                _thalamusClient.Debug("XMLRPC Listening on " + string.Format("http://*:{0}/", _localPort));
                _serviceRunning = true;
            }
            catch
            {
                _localPort++;
                _serviceRunning = false;
            }
        }

        while (!_shutdown)
        {
            try
            {
                HttpListenerContext context = _listener.GetContext();
                lock (_httpRequestsQueue)
                {
                    _httpRequestsQueue.Add(context);
                }
            }
            catch (Exception)
            {
                _serviceRunning = false;
                if (_listener != null)
                {
                    _listener.Close();
                }
            }
        }
    }